NEW
Also known as: Unit Test Cases
Executable checks validating small, isolated pieces of code against expected behavior.
DESCRIPTION
Unit tests are executable specifications that assert the behavior of individual functions, methods, or classes. They use assertions to verify outputs and side effects under controlled inputs. Fixtures prepare repeatable environments, while mocks and stubs isolate dependencies. Unit tests are organized and executed by test runners within CI pipelines. Good unit tests are fast, deterministic, and readable, serving as living documentation.
ALTERNATIVE DEFINITIONS
Atlassian
A unit test is a way of testing a unit — the smallest piece of code that can be logically isolated in a system.
Defines a unit test as an isolated verification of the smallest code unit.
JUnit
Tests focus on the smallest testable parts of software and verify their behavior via assertions.
Emphasizes assertions and smallest testable parts in the Java ecosystem.
RELATED TERMS
Test Case Assertion Mocking Stubbing Fixture Test Runner Code Coverage Regression Testing Continuous Integration
COMPETING TERMS
Integration Test End-to-End Tests
KNOWLEDGE AREAS
Testing & Validation Software Engineering Data Engineering
TARGET AUDIENCE
Software Developer Data Engineer MLOps Engineer DevOps Engineer Software Architect
EXTERNAL SOURCES
- Wikipedia - Unit testing
- pytest - Guide to writing unit tests in Python
- Jest - JavaScript unit testing documentation
TOP QUESTIONS
What is the primary goal of Unit Tests?
Unit Tests confirm that small, isolated code pieces behave as expected, providing fast feedback and preventing regressions.
Category: Overview
How should Unit Tests be structured?
Follow Arrange-Act-Assert, use clear naming, and keep tests independent with minimal shared state.
Category: Best practices
What tools run Unit Tests?
Common runners are pytest, JUnit, NUnit, and Jest. CI systems orchestrate execution and reporting.
Category: Platform
How many Unit Tests are enough?
Aim for meaningful coverage and strong assertions rather than arbitrary percentages. Coverage guides, but quality matters most.
Category: Opinion
What’s a common mistake in Unit Tests?
Testing implementation details instead of observable behavior leads to brittle tests.
Category: Mistakes
How do fixtures help Unit Tests?
Fixtures set up consistent test environments, reducing duplication and flakiness.
Category: Requirements
How do Unit Tests support refactoring?
They provide confidence to change internal structures while preserving external behavior.
Category: Benefits
Should Unit Tests touch databases?
Prefer isolating data access with mocks; database interaction belongs in integration tests.
Category: Risk
How are Unit Tests integrated in CI/CD?
Automate execution on each commit and fail builds on test failures to maintain quality.
Category: Management