Creating JUnit Test Cases using NetBeans

6 August 2007

In a Big project a programmer might need to test each component of our program independently from the rest of our program. In Java this is supported by JUnit Test cases.

In the design phase of the project every method is supposed to do some particular job and have also come up with a set of tests to ensure that method is functioning properly. JUnit provides a frame work to take each one of the methods and perform individual tests so that we can ensure that we are getting proper values.

http://junit.sourceforge.net/javadoc/index.html contains the API for the JUnit framework, the specification for Assert, JUnit, and TestCase etc can be found there.
NetBeans IDE provides an easy way to support JUnit testing .Here is the steps which should be followed to create Unit Tests

  1. At first make a Java Project in IDE. NetBeans automatically creates space for the test cases in “Test packages” folder where programmer can add the test cases for the classes.

    nb_blog001060807.jpg

  2. Now suppose you have some class for which you want to create test cases. Right click on Test Packages and click new file/Folder. You will see following Screen.

    nb_blog002060807.jpg

  3. Select Junit category and empty test as a file type. Click “Next” .You will see the following screen.

    nb_blog003060807.jpg

  4. Here you can browse the Java File for which you want to create test cases. You can also select the options for which you want to create. Here Click “Browse” button. Following screen will appear.

    nb_blog004060807.jpg

  5. Select the file for which you want to create the test cases .Press “Ok”.NetBeans will generate the test class in the same package as of the source file. You can open the file by going under the tree of Test packages in Java Project. You can edit as per your business logic you can also run it using “Run File” Option as shown below.

    nb_blog005060807.jpg

  6. You can see the Junit Result Window which will show the result of Junit Test case.

    nb_blog006060807.jpg

del.icio.us:Creating JUnit Test Cases using NetBeans digg:Creating JUnit Test Cases using NetBeans spurl:Creating JUnit Test Cases using NetBeans wists:Creating JUnit Test Cases using NetBeans simpy:Creating JUnit Test Cases using NetBeans newsvine:Creating JUnit Test Cases using NetBeans blinklist:Creating JUnit Test Cases using NetBeans furl:Creating JUnit Test Cases using NetBeans reddit:Creating JUnit Test Cases using NetBeans fark:Creating JUnit Test Cases using NetBeans blogmarks:Creating JUnit Test Cases using NetBeans Y!:Creating JUnit Test Cases using NetBeans smarking:Creating JUnit Test Cases using NetBeans magnolia:Creating JUnit Test Cases using NetBeans segnalo:Creating JUnit Test Cases using NetBeans gifttagging:Creating JUnit Test Cases using NetBeans

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Creating JUnit Test Cases using NetBeans

Leave a Reply