Traditional Culture Encyclopedia - Traditional stories - Unit test to measure one branch or multiple branches

Unit test to measure one branch or multiple branches

Unit testing measures multiple branches.

Unit tests are really white-box tests, where the developer knows the logic of their code, so they want to test as many logical branches or execution paths as possible.

In a traditional structured programming language like C, the unit to be tested is typically a function or sub-procedure. In an object-oriented language like C++, the basic unit of testing is the class. For Ada languages, developers can choose whether to perform unit testing at the level of standalone procedures and functions, or at the level of Ada packages.

Basic Information

A unit test (module test) is a small piece of code written by a developer to verify that a very small, well-defined piece of functionality of the code under test is correct. Typically, a unit test is used to determine the behavior of a particular function under a particular set of conditions. For example, you might put a very large value into an ordered list and confirm that the value appears at the end of the list.

Unit testing is done by the programmer, and ultimately benefits the programmer. It can be argued that the programmer's responsibility to write functional code carries with it the responsibility to write unit tests for his own code. Unit tests are executed to prove that the code behaves as we expect it to.