Junit Tutorial and Example

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

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 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.