Back to The Haunt
The craft3 min read

100% coverage, and the bug is still there.

Code coverage measures which lines ran while your tests ran. That is all. It does not know whether any test checked what those lines did.

Here is a test with 100% coverage of a discount function:

test('applies the discount', () => {
  applyDiscount({ total: 100, code: 'SAVE10' });
});

Every line of applyDiscount runs, so coverage reports 100%. There is no assertion, so the function could return anything and the test would still pass. Real suites are rarely this blunt, but the pattern is common: assertions that check a result exists, that a mock was called, or that nothing threw.

What the research says

The best-known study is Inozemtseva and Holmes, Coverage Is Not Strongly Correlated with Test Suite Effectiveness, from ICSE 2014. They generated 31,000 test suites for five large Java programs and measured how many artificial faults each suite caught. Once they accounted for the number of tests, the link between coverage and catching faults was low to moderate. Their conclusion: coverage is useful for finding code that is not tested, and a poor target for quality. Ten years later the paper won ICSE's Most Influential Paper award.

Google's code coverage guidance reaches the same place from practice. It offers 60% as acceptable, 75% as commendable and 90% as exemplary, calls coverage a lossy and indirect metric, and warns that pushing for 100% "leads to a false sense of security".

Why it matters more now

AI assistants are very good at raising coverage. Ask for tests and you get dozens, touching every branch, in minutes. Because they are often written by reading the code, they describe what the code does, bugs included, and their assertions lean towards the weak kinds above. A suite like that can lift coverage from 40% to 95% and catch almost nothing new.

Once coverage is a target, it becomes the easiest number for a person, or an agent, to satisfy without doing the real work.

How to use it well

  • Read the uncovered lines, not the percentage. Code no test touches is a real finding, and it tends to be error handling and rarely used branches.
  • Look at it per change. Coverage of the lines a pull request adds says more than one number for the whole project.
  • Use a floor, not a goal. A minimum stops the worst gaps. A mandate to reach a number gets you tests written to reach the number.
  • Measure whether tests can fail. For each new test, break the code it checks and watch it go red. Mutation testing does this at scale and lists the changes to your code that no test noticed.

Coverage answers "what did my tests run?" Mutation testing, and that one manual habit, answer "what would my tests catch?", which is the question you actually care about.

Chapters 10 and 11 of the free book Checked, Not Trusted cover tests that cannot fail and mutation testing in an afternoon, with labs. The Testing with AI guide puts the same checks into a team workflow.

That’s it. Come back soon; the ghost keeps writing.Follow by RSS

Read next.