Overview

A 'unit' is the smallest testable part of an application, such as a single function or method. Unit tests are typically automated and written by the developers themselves.

Characteristics

  • Fast: Should run in milliseconds.
  • Isolated: Should not depend on external systems like databases or APIs (use mocks/stubs).
  • Repeatable: Should always produce the same result for the same input.

Benefits

  • Catches bugs early in the development cycle.
  • Provides documentation on how the code is intended to be used.
  • Enables confident refactoring.

Related Terms