Back to the glossary

Test levels and methods

Unit test

A unit test checks the smallest testable unit of software, such as a function or class, in isolation from its dependencies and automatically within milliseconds.

Also known as: module test, component test

What makes a good unit test?

  • Fast: thousands of tests run in a few seconds.
  • Isolated: databases, network or hardware are replaced with mocks or stubs.
  • Deterministic: same input, same result, every run.
  • Informative: when the test fails, it is immediately clear what broke.

Its place in the test strategy

Unit tests form the broad base of the test pyramid. They catch logic errors early and cheaply and make refactoring safe. What they do not show is how the parts work together. That takes integration tests and system tests.

Unit tests for embedded code

Firmware can be unit tested well too, as long as hardware access is encapsulated behind interfaces. The logic then runs on the development machine or in CI, with no target hardware at all.