Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.
From Wikipedia:
Unit testing is a method by which individual units of source code are tested to determine if they are fit for use. Intuitively, one can view a unit as the smallest testable part of an application. In procedural programming a unit could be an entire module but is more commonly an individual function or procedure. In object-oriented programming a unit is often an entire interface, such as a class, but could be an individual method. Unit tests are created by programmers or occasionally by white box testers during the development process.
Ideally, each test case is independent from the others: substitutes like method stubs, mock objects, fakes and test harnesses can be used to assist testing a module in isolation. For example, these substitutes also known as Test Doubles can be used to isolate dependencies such as Databases and File System.
Unit tests are typically written and run by software developers to ensure that code meets its design and behaves as intended.Wikipedia.
Unit testing is closely related to Test Driven Development.
Benefits
The goal of unit testing is to isolate each part of the program and show that the individual parts are correct. A unit test provides a strict, written contract that the piece of code must satisfy. As a result, it affords several benefits.
- Finds problems early
- Facilitates change
- Simplifies integration
- Documentation
- Design
Books
There are a lot of books about unit test in general and about specific frameworks to specific languages, some examples are:
- Unit Test Frameworks - 2004
- The Art of Unit Testing With Examples in .NET - 2009
- Pragmatic Unit Testing in Java with JUnit - 2010
- Unittest in Python - 2010
- Python Testing with unittest, nose, pytest - 2014
- Starting to Unit Test: Not as Hard as You Think - 2014
External links