Junit is a most famous open source unit testing and regression testing framework in java, which was originally written by Erich Gamma and Kent Beck, it has became an industry standard framework which developers write repeatable tests and do white-box testing.
Never in the field of software development was so much owed by so many to so few lines of code. – artin Fowler
Junit features
1). Used for object-oriented technologies and Test Driven Development.
2). Assertions for testing expected results.
3). Test sharing common test data.
4). Able to manage multiple testcase as suite.
5). Provides Graphical and textual testing runner container.
6). Annotation to identify the test methods(After JUnit 4 ).
Some test concepts in Junit
Test fixture: a class that contains one or more test methods.
Test method: a method that executes a specific test.
Test runner: an application that find describes what must be action have been executed.
Expected Exception: the type of an Exception we expect to be execution of a test method.
Setup: Code that is run before every test method is executed particular user or initializing a singleton.
TearDown: Code that is run after every test method has finish from table that were inserted during the test.
Junit 3 vs Junit 4 Comparison
- Junit 3 vs Junit 4 Comparison
Junit 4 is the next series of Junit 3 and introduced lot of features
Junit 4.x tutorials and example
- Junit Tutorial 1 – Get starting
Introduces how to install junit and integrate with IDEA and eclipse, how to use Junit start the first test case. - Junit Tutorial 2 – Basic usage and annotation
Introduces basic concepts and annotation supported in Junit 4. - Junit Tutorial 3 – Expected Exception Test
Test the exception throw by the method in junit 4. - Junit Tutorial 4 – Junit Ignore test
Ignore certain test method for unit test. - Junit Tutorial 5 – Time and Parameterized Test
Introduces How do pass parameter value for unit test and make sure the testing method will run limitative certain time. - JUnit Tutorial 6 – Suite Test
How to bunch some test case together as one seize to run together.
Junit 4 in Ant
Reference
Using Junit do test-driven Development
Drive the deign and construction of your code on unit test at a time.
Write a test that the system currently fails.
Quickly write the code to pass the test.
Remove any duplication from the code.
Move on to the next test.