Unit testing in computing refers to a development process that assesses both the function and performance of the smallest discrete software module that can function on its own, also known as a unit. Since measurement is at the core of all software quality programs, each unit test verifies that a unit adheres to the design intention stated in the development plan. The test also validates that the unit behavior and performance is as expected.
Generally, unit tests are themselves small programs in which a developer specifies the acceptable inputs, behaviors, and outputs for the unit and then logs the results for later review and evaluation. A software developer can perform unit testing on an ad hoc basis, or if the main program is large or complex, he or she can add unit tests for inclusion in a larger test harness that exercises several integrated units at once. Regardless, unit testing is an ongoing effort by the developer to confirm that his or her code performs as expected, and as such, is considered an integral part of the overall development process.
Any software development process normally begins with a design phase in which the entire team spends its time writing down the plans for designing, developing, integrating, system testing, accepting, and maintaining new software. Unit testing is a necessary component of all phases. Developers must have a simple way to check that the code changes made in modules yield the anticipated results before integrating those changes into the main program.
Unit tests are usually written by the same developer whose code will be used. The reason for this is that the unit's programmer has in-depth understanding of the module's design and expected performance. Typically, the developer's test case sets the parameters for all the unit inputs, processing methods, and outputs, and defines the acceptable performance criteria for later integration and acceptance testing.
One key benefit of unit testing is that it encourages the discovery of problems early in the development process. When coding problems are discovered early, corrective actions and fixes usually can take place before buggy code has any negative effect on the integrated application and its users. Even though unit tests cannot catch every possible program error, they significantly reduce errors in later stages of the development process, saving time, money, and resources that would be required for debugging a program through additional validation and verification cycles before release.