Code Coverage
The proportion of code executed by a test suite — a map of what is untested, not a measure of quality.
Code coverage is the fraction of a codebase executed while the tests run, reported per statement, per line, per function, and per branch. It is produced by Instrumentation.
What it can tell you is narrow and genuinely useful: which code no test has ever run. Uncovered code is untested by definition. That is worth knowing.
What it cannot tell you is whether the covered code is correct. A test that executes a function and asserts nothing produces identical coverage to one that specifies it exactly. This is why coverage makes such a poor target — see Goodhart's Law and Coverage Gate.
Two mechanical facts save a lot of confusion. A failing test yields no coverage number at all: the reporter aborts before writing its summary, so an unrelated red test produces an absent measurement, not a threshold failure. And percentages are the wrong unit for diagnosis; the underlying per-position records are what actually explain a shortfall, and a report format that emits them is usually one flag away.
Coverage also behaves oddly across multiple test environments measuring the same files, where a single logical position can end up recorded twice; see Branch Coverage.
See also7
Hand-picked in the note itself — the neighbours worth reading next.
Branch Coverage
The proportion of conditional outcomes exercised — the strictest ordinary coverage metric, and the most informative.
Testing & Verification10 connections
Coverage Gate
A build check that fails when coverage falls below a threshold, and what that pressure produces.
Testing & Verification14 connections
Unreachable Code
Code no input can execute — usually a guard against a state the surrounding invariants forbid.
Testing & Verification10 connections
Instrumentation
Adding measurement to code so its execution can be observed, and the distortions that introduces.
Testing & Verification12 connections
Module Graph
The directed graph of imports that decides what code ends up where.
Web Platform16 connections
Regression
A previously working behaviour that a change has broken.
Method16 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
Related2
Nearby in the graph rather than deliberately chosen. Looser, sometimes surprising.
Linked from11
Notes elsewhere in the wiki that reach for this one.
- Branch CoverageTesting & Verification
The proportion of conditional outcomes exercised — the strictest ordinary coverage metric, and the most informative.
- Coverage GateTesting & Verification
A build check that fails when coverage falls below a threshold, and what that pressure produces.
- Goodhart's LawMethod
When a measure becomes a target, it stops being a good measure.
- InstrumentationTesting & Verification
Adding measurement to code so its execution can be observed, and the distortions that introduces.
- Integration TestTesting & Verification
A test exercising several components together, through real interfaces rather than doubles.
- Module GraphWeb Platform
The directed graph of imports that decides what code ends up where.
- RegressionMethod
A previously working behaviour that a change has broken.
- 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.
- Unit TestTesting & Verification
A fast, isolated test of one unit of behaviour with its collaborators replaced.
- Unreachable CodeTesting & Verification
Code no input can execute — usually a guard against a state the surrounding invariants forbid.