Code Coverage Myths: What the Number Really Tells You
Coverage measures which lines ran, not whether they were verified. Learn what it is good for, what it hides, and how to use it sensibly.
By Velloreth
What coverage measures
Code coverage measures which parts of your code were executed while the test suite ran.
- Line coverage — which lines ran.
- Branch coverage — which decision outcomes were taken.
- Function coverage — which functions were called.
- Statement coverage — which statements ran.
The number is a percentage: the proportion of lines (or branches) that the tests executed.
What it does not measure is whether the behaviour was correct. A line that ran is a line that ran. Whether the result was right is a separate question that coverage cannot answer.
The central myth
The myth is that high coverage means well-tested code.
function divide(a: number, b: number): number {
if (b === 0) throw new Error('Division by zero');
return a / b;
}
// 100% line coverage, 50% branch coverage, zero real verification
test('divide runs', () => {
divide(10, 2);
});
This test executes the function and asserts nothing. Line coverage for divide is 100% — every line ran except the throw. The test would pass if divide returned NaN, or 0, or threw for every input.
Coverage says the code ran. It says nothing about whether it worked.
Coverage versus verification
The gap between execution and verification is where the myth lives.
// Covers the line, verifies nothing
test('formats a date', () => {
formatDate(new Date());
});
// Covers the line and verifies the behaviour
test('formats a date as ISO', () => {
expect(formatDate(new Date('2026-01-15'))).toBe('2026-01-15');
});
Both give the same coverage. Only the second catches a bug.
This is why coverage can be high while the test suite is weak. The metric counts execution, and execution is easy to achieve.
Branch coverage is better
Line coverage has a specific blind spot: it does not require both outcomes of a decision.
function isEligible(age: number): boolean {
return age >= 18; // one line
}
test('checks eligibility', () => {
isEligible(20); // only the true case
});
Line coverage: 100%. The line ran. But the false case was never exercised, so a bug that always returns true would not be caught.
Branch coverage would report 50%, because only one of the two outcomes was taken. That is a more honest number.
Even branch coverage has limits. It does not require meaningful assertions, and it does not cover combinations of conditions.
What coverage hides
Weak assertions. As shown above, a test can execute code without verifying anything.
Missing edge cases. A function tested with one input has full line coverage and no boundary testing.
Untested error paths. Error handling is often the least covered code, and it is where production failures happen.
Integration gaps. Coverage is per-file. Every file can be 100% covered while the integration between them is broken.
Wrong behaviour. A test that asserts the current (buggy) behaviour gives full coverage and locks in the bug.
Dead code. Code that is never called in production can be covered by tests, which makes it look maintained.
Why chasing a target backfires
When coverage becomes a target, it stops being a measurement.
Tests written for the metric. Developers write tests that execute lines rather than verify behaviour, because that is what moves the number.
Assertion-free tests. The fastest way to raise coverage is to call functions without asserting. This is common when a threshold is enforced.
Excluding code. Coverage tools let you exclude files. A team under pressure will exclude the hard-to-test code, which is exactly the code that needs tests.
Gaming the denominator. Refactoring code into fewer lines, or moving logic into already-covered files, raises the percentage without adding tests.
Demoralising the team. A coverage gate that blocks merges creates friction and encourages workarounds.
This is Goodhart’s law: when a measure becomes a target, it ceases to be a good measure.
What coverage is good for
Finding untested code. A file at 0% coverage is a file with no tests. That is a reliable signal.
Spotting gaps in a change. A pull request that adds 200 lines and 0% coverage is worth questioning.
Tracking a trend. Coverage falling over time suggests tests are not keeping up with the code.
Prioritising. The lowest-covered, highest-risk modules are the best places to add tests.
The common thread: coverage is useful as a diagnostic, not as a goal.
Better measures
Mutation testing. Deliberately introduce small bugs and check whether the tests catch them. A test suite that catches 90% of mutations is genuinely effective; coverage cannot tell you this.
// Original
return a / b;
// Mutant 1: return a * b; — does a test catch it?
// Mutant 2: return a / (b + 1); — does a test catch it?
Tools: Stryker (JavaScript), PIT (Java), mutmut (Python).
Assertion density. The number of assertions per test. A test with no assertions is a smell.
Defect escape rate. How many bugs reach production. This is the outcome that matters, and it is the metric coverage is a proxy for.
Test runtime. A suite that takes 20 minutes will not be run. Speed is a real quality attribute.
A sensible policy
Do not enforce a high threshold. A gate at 90% produces tests written for the metric.
Consider a low floor. A floor at 50–60% prevents coverage from collapsing, without encouraging gaming.
Review coverage on changes. A pull request that adds significant code with no tests deserves a question.
Use it to find gaps. Run the report periodically and look at the lowest-covered, highest-risk files.
Prefer branch coverage over line coverage, since it is harder to game.
Do not report it as a quality metric in dashboards, where it will be treated as a target.
Practical guidance
- Treat coverage as a diagnostic, not a goal.
- Prefer branch coverage over line coverage.
- Do not enforce a high threshold — it produces tests written for the metric.
- Use it to find untested code, especially in high-risk modules.
- Check coverage on changes, not just in aggregate.
- Consider mutation testing for a real measure of test effectiveness.
- Remember that coverage says nothing about correctness — only that code ran.
For the related practices, see unit testing basics and test-driven development guide. For the broader context, integration vs unit tests and why your tests are slow.
Quotable summary
Code coverage measures which lines, branches, or functions were executed by the test suite, not whether their behaviour was verified. High coverage with weak assertions is entirely possible, because a test that calls code and asserts nothing covers lines without testing them. Low coverage is a reliable signal that code is untested; high coverage is not proof of quality. Chasing a coverage target produces tests written to satisfy the metric rather than to catch bugs, which is Goodhart’s law in action. Use coverage to find untested areas and to spot gaps in a change, prefer branch coverage over line coverage, and consider mutation testing for a real measure of test effectiveness.