Unit Test

Noun · Development

Definitions

  1. Unit Test is an automated test that verifies the behavior of a small, isolated piece of code, typically a single function, method, or class, in isolation from the rest of the system. Unit tests are the foundation of the testing pyramid, being the fastest to run, cheapest to maintain, and most numerous in a well-tested codebase. Each test typically follows the Arrange-Act-Assert pattern: set up the inputs and dependencies, execute the code under test, and verify the output matches expectations. Dependencies on databases, APIs, or file systems are replaced with test doubles (mocks, stubs, fakes) to ensure tests run quickly and deterministically. Good unit tests are fast (running in milliseconds), independent (not reliant on other tests), repeatable (same result every time), and focused on a single behavior. Frameworks include JUnit (Java), pytest (Python), Jest (JavaScript), and xUnit (.NET). Unit tests serve as living documentation of how code is expected to behave and provide a safety net for refactoring.

    In plain English: An automated check that tests one small piece of code in isolation to make sure it does what it's supposed to.

Related Terms