JUnit is an open source Java testing framework used to write and run repeatable tests.
Why JUnit
- Tests should be written before the code. Test-first programming is practiced by only writing new code when an automated test is failing.
- Inserting debug statements into code is a low-tech method for debugging it. It usually requires that output be scanned manually every time the program is run to ensure that the code is doing what's expected.
- It generally takes less time in the long run to codify expectations in the form of an automated JUnit test that retains its value over time. If it's difficult to write a test to assert expectations, the tests may be telling you that shorter and more cohesive methods would improve your design.
- Test everything that could reasonably break.
- Be practical and maximize your testing investment. Remember that investments in testing are equal investments in design. If defects aren't being reported and your design responds well to change, then you're probably testing enough. If you're spending a lot of time fixing defects and your design is difficult to grow, you should write more tests.
JUnit Test and TestSuites
- Once you have created your JUnit test you can run it individually or as part of a suite of tests. In addition, suite of tests can be added as subsets of other suites. Breaking suites down into logical subsystems.
- A suite of tests can be made to test the entire system at once.