Unit testing is a software testing method by which individual units of source code, together with associated control data, usage procedures, and operating procedures, are tested to determine whether they are fit for use.
A unit is the smallest testable part of an application. In procedural programming, a unit could be an entire module, or an individual function or procedure. In object-oriented programming, a unit is often a class, but could be an individual method. (source = Wikipedia).
Some of the properties of good unit tests are:
- Unit tests should be fully isolated. They should run independently of other tests.
- When it fail, it should give proper indication of what has failed and what was the expectation.
- Unit test should only test a single unit at a time. There should not be any real dependency.
- It should continue to run consistently always as long as the functionality of the unit has not changed.
- Unit tests should be faster and easier to run. There should not be need to configure any machine or create a setup for running tests.
- Unit testing is usually automated and is usually done using an unit testing framework.
Popular unit testing frameworks or helper libraries in Java
- Spring Test