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:
- Test Case Class: Named [classname]Test.java, where classname is the name of the class that is being tested.
- Test Case Method: Named test[methodname], where methodname is the name of the method that is tested.
- Test Suite: Default name for Eclipse is AllTests.java.
- Test Set Up: setUp(),Called before every test case method.
- 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:
- Test Case Class: Named [classname]Test.java, where classname is the name of the class that is being tested.
- Test Case Method: Annotate the method with @Test. The method name does not have to start with test.
- Test Suite: Only write a suite() method if you want to run your JUnit 4 tests with the JUnit 3.8 test runner.
- Test Set Up: Annotate the method with @Before .
- Test Tear Down: Annotate the method with @After .
No comments:
Post a Comment