JUnit is a framework for implementing testing in
It provides a simple way to explicitly test specific areas of a Java
program, it is extensible and can be employed to test a hierarchy of program
code either singularly or as multiple units.
Why use a testing framework? Using a testing
framework is beneficial because it forces you to explicitly declare the expected
results of specific program execution routes. When debugging it is possible to
write a test which expresses the result you are trying to achieve and then debug
until the test comes out positive. By having a set of tests that test all the
core components of the project it is possible to modify specific areas of the
project and immediately see the effect the modifications have on the other areas
by the results of the test, hence, side-effects can be quickly realized.
JUnit promotes the idea of first testing then
coding, in that it is possible to setup test data for a unit which defines what
the expected output is and then code until the tests pass. It is believed by
some that this practice of "test a little, code a little, test a little, code a
little..." increases programmer productivity and stability of program code
whilst reducing programmer stress and the time spent debugging.