Printed from A Developer website designed for Developers

Introduction to Unit Testing

Unit Testing Explained

Unit testing is done by developers, for other developers.

A unit test is a piece of code written by a developer that exercises a very small, specific area of functionality in the code being tested. The purpose is to prove that the code does what it is intended to do. By building up confidence in individual pieces of code, we can proceed to test the entire working application.

Unit tests will make for better designed code and drastically reduce the amount of time spent debugging code. Furthermore, unit tests help communicate the code's intended use, showing how the code is expected to behave under various conditions.

Unit tests should be organized around behaviours, and not necessarily around individual methods.

Effective unit tests have the following properties:

There are specific areas that need to be tested:

Where to Put Test Code