Unit Testing

This section provides an overview of software testing, describes unit testing and its place in the testing cycle, provides an overview of test driven development, and recommends best practices for unit testing.

Testing Software

Software testing measures the performance of software against both functional and nonfunctional acceptance criteria. Unit testing ensures that software does what it commits or is expected to do.

Successful unit testing starts with acceptance criteria that you identify during the requirements analysis; the acceptance criteria and the requirements are specified together. Acceptance criteria must be measurable—a statement such as "the software must perform well" is not enough. You must identify each combination of inputs and the expected output, and the final state for each based on the starting state.

Testing is approached from two different but complementary focuses:

White box

Tests the unit, component, or system by looking at what happens within the code. Tests are determined based on how functionality is actually implemented. The flow of both control and data within the code is tested. In addition to verifying inputs and outputs, you can examine all code paths, and see exactly how the code processes the inputs to generate the outputs, how errors are raised and propagated, and the internal state of the code after it has been executed.

Black box

Examines the behavior of a unit, component, or system from a functional perspective—this is why such tests ...

Get NUnit Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.