JetBrains

Unit Testing

In computer programming, unit testing is a procedure used to validate that individual units of source code are working properly. A unit is the smallest testable part of an application. In procedural programming a unit may be an individual program, function, procedure, etc., while in object-oriented programming, the smallest unit is a method, which may belong to a base/super class, abstract class or derived/child class.

Ideally, each test case is independent from the others; mock objects can be used to assist testing a module in isolation. Unit testing is typically done by developers and not by software testers or end-users.

There are unit test frameworks like TestNG, JUnit or NUnit to create automated unit tests suites.

Unit tests are one of the corner stones of Extreme Programming (XP).

Although generally you should test all system classes some parts do not need to be covered including trivial getter and setter methods. Unit tests are written before the business code. This is called Test First (or Test-Driven Development). Unit tests are released into the code repository along with the code they test. Unit tests do enable collective code ownership. Automated unit tests offer a pay back far greater than the cost of creation. Tests can be automated by TeamCity.

The test coverage can be examined by tools like EMMA. Test Coverage metrics are available in IntelliJ IDEA.