What Coverage Measures

Coverage measures which lines ran, not whether anything was checked. A test that calls every function and asserts nothing reports high coverage and tests nothing at all.

It is genuinely useful in one direction: uncovered lines are definitely untested, and looking at them often finds a branch you forgot existed. It is not useful in the other: covered lines may still be entirely unverified.

✦ Coverage as a target stops working the moment it becomes one

Mandate ninety percent and people write tests that execute lines without checking behavior, because that is the cheapest way to hit the number. You then have a slower suite, a false sense of safety, and the same bugs. Use it to find gaps, not to score.

Branch coverage is more informative than line coverage. A line with an if on it counts as covered when either branch runs, so line coverage can be high while half the conditions have never been exercised.

What to actually look at: the uncovered branches in code where being wrong is expensive.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Flaky Tests →
← Back