Saturday, December 31, 2011

About JUnit


JUnit is an open source unit testing framework for automatically unit testing Java programs.  
JUnit provides functionality for writing and running unit test cases for a project under development.

Mainly there are two versions of JUnit
I.JUnit3
II.JUnit4

I.JUnit 3 uses specific naming conventions for identifying test classes, methods, and suites.
These naming conventions are described below:
  1. Test Case Class: Named [classname]Test.java, where classname is the name of the class that is being tested.
  2. Test Case Method: Named test[methodname], where methodname is the name of the method that is tested.
  3. Test Suite: Default name for Eclipse is AllTests.java.
  4. Test Set Up: setUp(),Called before every test case method.
  5. Test Tear Down: tearDown(),Called after every test case method.

II.JUnit 4 uses annotations (which are keywords that start with @) to identify test classes, methods, and suites.The key annotations are described below:
  1. Test Case Class: Named [classname]Test.java, where classname is the name of the class that is being tested.
  2. Test Case Method: Annotate the method with @Test. The method name does not have to start with test.
  3. Test Suite: Only write a suite() method if you want to run your JUnit 4 tests with the JUnit 3.8 test runner.
  4. Test Set Up: Annotate the method with @Before .
  5. Test Tear Down: Annotate the method with @After .


No comments:

Post a Comment