Quality Engineering | What Code Coverage Misses...

What Code Coverage Misses

What 93% coverage conceals: the gap between code your tests visit and bugs they would actually catch

A towering green percentage meter glowing on a boardroom wall while beneath the floorboards a deep chasm reveals broken components and undetected faults.
Green coverage dashboards reward visiting code rather than catching defects, leaving logic errors undetected behind a wall of passing assertions.

Software engineers learned long ago that you cannot improve what you cannot measure. Boards took that lesson and ran with it, straight into the wrong metric. Code coverage (the percentage of source lines executed during a test run) now adorns dashboards from Silicon Valley to Singapore as the primary signal of software health. Mandate 80%, watch the number climb, congratulate the team, and file the slide. The ritual is reassuring, repeatable, and wrong. Code coverage is the BMI of software quality (a comparison Jared Toporek drew on the Stack Overflow blog, and it deserves to stick): a single number that feels scientific, correlates poorly with what actually matters, and is optimised above all else for its own improvement. Achieving a high score demands nothing so inconvenient as tests that catch bugs, merely tests that visit code. The board’s comfortable green dashboard may be the most expensive misunderstanding in modern engineering, and the industry has spent two decades building governance architecture on top of it.

What Coverage Can Tell Us

Coverage can highlight code that tests never execute. A coverage threshold alone cannot establish that tested behaviour is correct or that production defects are unlikely. The right threshold and its use depend on the codebase and the risks being managed.

Investigating Test Sensitivity

Mutation testing introduces small, deliberate changes into source code and checks whether tests detect them. It can reveal weaknesses that coverage alone cannot. In a practitioner case study by J. Ghiringhelli, a codebase reporting 93.1% line coverage yielded a 58.62% mutation score. The two percentages use different denominators: their numerical difference is not the fraction of the codebase containing undetected bugs. The example nevertheless shows why executing a line does not guarantee that a test detects a change to its behaviour. Researchers at Carnegie Mellon and Northern Arizona University study the difference between coverage and mutation score as an “oracle gap” that can help guide investigation. Google’s mutation-testing system generates mutants on covered lines, some of which survive. A surviving mutant merits investigation, although it can also be equivalent to the original code or irrelevant to the behaviour under test.

The Perverse Machine

AI-assisted tools can produce tests quickly, including tests that rely heavily on mocks. Review those tests for meaningful assertions and realistic boundaries; the amount of generated code or reported coverage does not establish its effectiveness.

The deeper problem is not the metric itself but the governance architecture built around it. When coverage becomes a deployment gate, a performance-review line item, or a board-level KPI, it stops being a signal and becomes a target. Goodhart’s Law, the observation by economist Charles Goodhart that any measure which becomes a target ceases to be a good measure, operates without mercy on software quality. Coverage was never a particularly good measure to begin with. Promoted to a target, it is actively harmful.

The honest counter-case deserves the floor. The same Google group found coverage genuinely useful as developer feedback (Code Coverage at Google, ESEC/FSE 2019), and its mutation service pointedly computes no mutation score at all: coverage decides which lines get mutated, and the authors call mutation adequacy neither practical nor desirable. Mutation score is itself an imperfect proxy with a contested link to real faults. Coverage and mutation results offer different clues, with different denominators and limitations. Use them to investigate concrete gaps in tests, rather than treating their numerical difference as a defect rate or proof of production quality.

The Monday version of this is checkable. Pick a critical service and run a mutation testing tool (such as PIT for Java, Stryker for JavaScript/TypeScript/C#, or mutmut for Python) against its core domain logic. Review surviving mutants for missing assertions or scenarios, and distinguish meaningful survivors from equivalent or irrelevant changes. Use coverage to find unexecuted code and mutation results to investigate test sensitivity; neither percentage alone proves production quality.

For a related discussion of metric incentives, see Coverage Obsession.

References

  1. Ghiringhelli, I Had 93% Test Coverage. Then I Ran Mutation Testing.
  2. Jain et al., Mind the Gap: The Difference Between Coverage and Mutation Score Can Guide Testing Efforts, 2023.
  3. Petrović et al., Practical Mutation Testing at Scale: A View from Google, 2021.

More from Quality Engineering →

Ouray Viney

Quality Engineering leader with 20+ years experience in software testing and automation

Discussion