Testing code as it is being developed, before it goes to QA, can improve code quality and drastically reduce maintenance and debug time.
A unit test:
Is highly localized
Is designed to test code only within a single package
Does not test interactions between packages (functional testing does that)
JUnit is the most popular framework for unit testing, enabling developers to write and run repeatable tests. Its features include:
Assertions to test expected results
Fixtures for sharing test data
Test suites that organize and run tests
Graphical and textual test runners
JUnit works by performing many small tests, reporting success or failure of each; it is not intended to report multiple failures per test. Improving the testability of code usually results in better design.
JUnit enables you to automate tests for repeatability and to collect tests into suites for regression testing.