Testing Glossary
Unit Test
A fast, isolated test that verifies the correctness of a single function, method, or small piece of logic independently from the rest of the system.
A unit test validates the smallest testable piece of an application — typically a single function or method — in complete isolation from external dependencies. Unit tests are the foundation of the test pyramid and are characterized by being fast, deterministic, and easy to write and maintain.
Characteristics of Good Unit Tests
Effective unit tests are fast, running in milliseconds rather than seconds. They are isolated, meaning they do not touch databases, file systems, network services, or other external resources. Dependencies are replaced with test doubles such as mocks, stubs, or fakes. They are repeatable, producing the same result every time regardless of the environment or execution order.
Why Unit Tests Are Essential
Unit tests provide the tightest feedback loop in the development process. A developer can run hundreds of unit tests in seconds, catching errors moments after they are introduced. This speed makes them ideal for test-driven development (TDD), where tests are written before the implementation.
Because unit tests exercise code in isolation, failures pinpoint the problem precisely. When a unit test fails, the developer knows exactly which function broke and can debug without wading through layers of infrastructure.
Unit Tests in CI
Unit test suites are typically the first to run in a CI pipeline. Their speed makes them a natural first gate — if a unit test fails, the build stops before slower integration or end-to-end tests consume resources. Most projects aim for high unit test coverage of business logic and algorithmic code, while leaving infrastructure and wiring to integration tests.
Limitations
Unit tests cannot catch problems that arise from component interaction. A function might pass all unit tests but fail when connected to a real database or called by another service with unexpected inputs. This is why unit tests are complemented by integration and end-to-end tests, forming a balanced test strategy.
Monitoring unit test metrics — count, duration, pass rate, and flakiness — helps teams maintain a healthy, fast inner development loop.
Related Terms
Monitor Your Test Suite Health
TestGlance tracks test results, detects flaky tests, and surfaces health trends automatically.
Get Started