Unit Test
A fast, isolated test of one unit of behaviour with its collaborators replaced.
A unit test exercises a small piece of behaviour 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 behaviour, 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 behaviour — 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
Hand-picked in the note itself — the neighbours worth reading next.
Integration Test
A test exercising several components together, through real interfaces rather than doubles.
Testing & Verification9 connections
Test Double
A stand-in for a real dependency during a test — and the ways a stand-in can lie.
Testing & Verification10 connections
Test-Driven Development
Writing a failing test first, making it pass, then improving the code with the test as a net.
Testing & Verification9 connections
Component Story
An isolated rendered instance of a component, usable as documentation, a workbench, and a test.
Testing & Verification15 connections
Related3
Nearby in the graph rather than deliberately chosen. Looser, sometimes surprising.
Linked from8
Notes elsewhere in the wiki that reach for this one.
- Code CoverageTesting & Verification
The proportion of code executed by a test suite — a map of what is untested, not a measure of quality.
- 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.
- Responsive BreakpointDesign & Interface
A viewport width at which a layout changes, and the assumptions that come with it.
- 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.