Unit Test
A fast, isolated test of one unit of behavior with its collaborators replaced.
A unit test exercises a small piece of behavior in isolation, with anything slow or external replaced by a Test Double. Its virtues are speed and precision: thousands run in seconds, and a failure names a narrow location.
The perennial argument is about what counts as a unit. Taken as "one function", the result is a suite bound to internal structure, which breaks on every refactor and prevents the change it was supposed to protect. Taken as "one behavior, at whatever boundary is stable", the suite survives implementation changes and stays useful. The second reading is the one that ages well.
Unit tests are best suited to pure logic: reducers, adapters, parsers, calculations, anything whose inputs and outputs are values. They are poorly suited to anything whose correctness depends on a real environment — layout, focus, styling, browser behavior — where the double diverges from reality and the test passes while the product is broken.
There is also an environmental cost worth knowing about. A unit test that imports a user-interface module drags that module into the unit environment, which can distort coverage measurement for files nobody touched. Importing a value from the package that owns it, rather than through a component barrel, avoids the whole class of problem. See Code Coverage and Tree Shaking.
See also4
Integration Test
A test exercising several components together, through real interfaces rather than doubles.
Testing & Verification12 connections
Test Double
A stand-in for a real dependency during a test — and the ways a stand-in can lie.
Testing & Verification12 connections
Test-Driven Development
Writing a failing test first, making it pass, then improving the code with the test as a net.
Testing & Verification10 connections
Component Story
An isolated rendered instance of a component, usable as documentation, a workbench, and a test.
Testing & Verification16 connections
Related4
Nearby in the graph rather than deliberately chosen. Looser, sometimes surprising.
Linked from15
- Binary SearchComputation & Algorithms
Finding a value in a sorted range by repeatedly discarding half of it.
- Code CoverageTesting & Verification
The proportion of code executed by a test suite — a map of what is untested, not a measure of quality.
- Contract TestingTesting & Verification
Verifying that a service and its consumer agree on an interface's shape, without either side needing the other running to test against.
- Headless BrowserTesting & Verification
A real browser driven programmatically without a visible window.
- Integration TestTesting & Verification
A test exercising several components together, through real interfaces rather than doubles.
- MonadComputation & Algorithms
A wrapper type with a way to lift a value in and a way to chain functions that return more wrappers.
- Mutation TestingTesting & Verification
A test-of-tests that injects small bugs into code and checks whether the existing suite catches them, exposing tests that assert nothing.
- Property-Based TestingTesting & Verification
Asserting a general property that should hold for all inputs, then letting the framework generate many random inputs to try to break it.
- Pure FunctionComputation & Algorithms
A function whose output depends only on its input and which causes no observable effect outside itself.
- Responsive BreakpointDesign & Interface
A viewport width at which a layout changes, and the assumptions that come with it.
- Smoke TestTesting & Verification
A fast, shallow check that a build isn't catastrophically broken, run before investing in a deeper test pass.
- Test DoubleTesting & Verification
A stand-in for a real dependency during a test — and the ways a stand-in can lie.
- Test FixtureTesting & Verification
The prepared data or state a test runs against.
- Test-Driven DevelopmentTesting & Verification
Writing a failing test first, making it pass, then improving the code with the test as a net.
- Tree ShakingWeb Platform
Statically removing exports that nothing imports, shrinking the shipped bundle.