A green report doesn't mean
a correct program.
Code coverage tells you which lines your tests ran — never which lines your tests actually proved correct. It's a flashlight for finding untested code, not a certificate of quality. This chapter is the case for using the number honestly: chase the gaps it reveals, ignore the temptation to worship the percentage itself.
What code coverage actually measures
Lock in the exact definition first — it's the anchor for every argument in this chapter.
The percentage of your codebase exercised by tests
Code coverage identifies the percentage of your codebase that was exercised — meaning executed, not necessarily verified — by a test suite. That percentage is what gets displayed in a coverage report.
It's often a gate, not just a diagnostic
On product delivery teams, developers are frequently required to back the code they write with unit/integration/e2e tests. Some teams go further, requiring every incoming branch to meet a coverage threshold — trusting (often wrongly) that a high percentage eliminates bugs from the production codebase.
Coverage is helpful. Chasing the percentage is not.
This is the single idea the whole deck circles back to — get it airtight.
The real, practical benefits
Finds untested code
Helps developers see what portions of the codebase are covered by unit tests — and, just as usefully, what isn't.
Orients you on a new project
The first thing to do when rolling onto an existing project: run a coverage report to see where testing focus should go.
Pinpoints weak files/components
Reports break the percentage down by branches, statements, and functions, making it easy to spot which files or components lack tests.
Automates CI/CD gating
A pipeline can automatically fail a branch with low coverage, keeping the production branch purer.
Falls out of TDD naturally
Teams practicing Test-Driven Development should sit around 80%-90% coverage automatically — though language/framework quirks can keep even TDD teams from hitting a "clean" 100%.
Frames the client conversation
Some clients want a high coverage percentage — that's fine. As developers/consultants, the job is helping them understand what an application solution actually needs.
Spec first, coverage second
The order of operations here is exactly the kind of thing an exam question will try to flip on you.
The deep-dive: nine rules from the industry playbook
Code coverage is a "surprisingly polarizing topic" among engineers — these rules exist to move the conversation past the arguing and into using coverage pragmatically.
1 · A useful metric — but an indirect one
benefits & limitsCoverage isn't a perfect measure of test quality, but it is a reasonable, objective, industry-standard metric with actionable data. It needs little human interaction, applies universally across products, and has ample tooling for most languages.
2 · Culture change, not a guaranteed defect cure
open research questionWhether coverage alone reduces defects is genuinely an open research question. But experience shows that efforts to increase coverage often trigger culture changes that do reduce defects in the long run.
3 · High % ≠ high quality
the false-security trapChasing 100% leads to a false sense of security, and can be wasteful — burning machine cycles and creating technical debt from low-value tests that now need maintenance.
4 · Low % does guarantee a problem
the flip sideWhile high coverage doesn't guarantee quality, a low coverage number does guarantee that large areas of the product go completely untested by automation on every deployment — raising the real risk of pushing bad code to production.
5 · No universal "ideal number"
context-dependent targetThere is no single coverage percentage that's right for every product. The right level of testing for a piece of code should be a function of three things.
6 · Google's general guideline scale
60 / 75 / 90In general, coverage across a lot of products is below the bar — the aim should be significant improvement across the board. While there's no single "ideal" number, Google offers general guidelines:
| 60% | 75% | 90% |
|---|---|---|
60% "Acceptable" |
75% "Commendable" |
90% "Exemplary" |
7 · Diminishing returns near the top
90% → 95% isn't worth itDon't obsess over squeezing 90% coverage up to 95% — the gains of increasing coverage beyond a certain point are logarithmic. The better use of effort is taking concrete steps to move a weak area from 30% to 70%, and making sure new code always meets the team's desired threshold.
8 · Human judgment beats the raw number
code review integrationMore important than the percentage of lines covered is human judgment over the actual lines of code (and behaviors) that aren't covered — analyzing the gaps and deciding whether that risk is acceptable. What's not covered is more meaningful than what is.
9 · Legacy code, frequency, scope, and gating
the operational rulesFour closely related closing rules, all about applying coverage in the real world.
Every number and rule, in one table
| Concept | Rule / Number |
|---|---|
| Coverage report is built from | Branches, Statements, Functions, Lines |
| TDD teams naturally land around | 80%–90% coverage |
| Google — "acceptable" | 60% |
| Google — "commendable" | 75% |
| Google — "exemplary" | 90% |
| Reasonable per-commit goal | 99% (90% as lower threshold) |
| Returns beyond ~90% | Logarithmic — not worth obsessing over |
| Better focus than 90%→95% | Move weak areas from 30%→70% |
| Technique for "covered but not tested correctly" | Mutation testing |
| Minimum move on inherited legacy code | Boy-scout rule (leave it cleaner than found) |
| 3 factors that set the "right" target | Business impact/risk · change frequency · lifespan & complexity |
| What matters most in a gap | Human judgment on what's not covered, in code review |
Where students (and teams) actually get this wrong
These are the exact mix-ups this chapter is built to prevent.
Quick self-check
Click a question to reveal the answer.
Apply the rules to realistic scenarios
Same shape of reasoning an exam question would ask for — grounded directly in the slide content.