Published
Test Coverage Metrics: Which Ones to Track and Which to Ignore
Short answer
Test coverage metrics fall into three groups: structural metrics that count executed code (statement, line, branch, function), fault-detection metrics such as mutation score, and behavior metrics such as requirement or scenario coverage. Structural metrics tell you what no test ran. They cannot tell you whether the tests that did run check anything, so pair them with mutation testing and a map from tests to the behavior you promised.
Last updated: 2026-11-13
What are the main test coverage metrics?
Coverage is not one number. Each metric counts a different unit, and each one misses something the others catch.
| Metric | What it counts | What it misses |
|---|---|---|
| Statement coverage | Executable statements run at least once | The untaken side of a condition |
| Line coverage | Lines containing executable code that ran | Several statements or branches on one line |
| Branch coverage | Each true and false outcome of an if, ternary or logical operator | Individual conditions inside a compound test |
| Function coverage | Functions or methods called at least once | Almost all logic inside those functions |
| Mutation score | Share of deliberately injected faults that a test fails on | Behavior the code never implemented |
| Requirement or scenario coverage | Requirements, user stories or scenarios with at least one linked test | Whether the linked test checks the right thing |
The web.dev testing guide lists the same four structural types (function, line, branch and statement) and makes a useful distinction. Code coverage measures how much code your tests execute. Test coverage, in the broader sense, describes how well the suite covers the features of the software. Many teams use the two terms interchangeably, so check which one a dashboard means before you act on it.
How do line coverage and branch coverage differ?
Line coverage can be 100% while half the decisions in the code were never exercised. Take a function with one if and no else:
function shippingFee(total) {
if (total < 50) return 5;
return 0;
}
A single test with total = 20 runs every line, so line coverage is 100%. Branch coverage is 50%, because the path where total is 50 or more never ran. A bug in that path would ship unnoticed.
Istanbul, the most widely used JavaScript coverage library, reports statements, branches, functions and lines side by side, so you can see the gap. When the numbers disagree, trust the lower one. For decision-heavy code such as pricing, permissions and validation, branch coverage is the more informative of the two.
Why does 100% coverage not mean the code is tested?
Coverage only records that code ran. The Google Testing Blog says it directly: code coverage does not guarantee that the covered lines or branches have been tested correctly, only that a test executed them.
This test gives full coverage of shippingFee and checks nothing:
test('runs', () => {
shippingFee(20);
shippingFee(80);
});
No assertion means no failure if the function returns the wrong value. Coding agents make this easy to produce at volume: they are good at writing tests that execute code, and a reviewer reading a coverage badge will not see that the assertions are weak.
What is mutation score and when should you use it?
Mutation testing changes your code on purpose (flips < to <=, deletes a return, swaps true for false) and reruns the tests. If a test fails, that mutant is killed. If every test still passes, the mutant survived, which means no test would notice that bug. Mutation score is the share of mutants killed.
Google's testing blog points to Pitest for Java and Stryker Mutator for JavaScript as mature open-source tools. Mutation runs are much slower than ordinary coverage runs, because the suite runs once per mutant. Most teams run them on changed files in a nightly or pull request job rather than on every commit, and apply them to the logic that matters most: money, permissions, data integrity.
How do you measure coverage for end-to-end tests?
For JavaScript web apps, Playwright exposes JavaScript and CSS coverage through page.coverage. Playwright's documentation notes that these coverage APIs are supported only on Chromium-based browsers, so run coverage collection on a Chromium project rather than across every browser. The raw V8 data can be converted to an Istanbul report with the v8-to-istanbul package, and Istanbul's nyc or the c8 tool can produce HTML, LCOV and text summaries.
Two cautions apply:
- Browser coverage counts the frontend code that executed. Backend routes your UI tests call are not included unless you collect coverage on the server too.
- End-to-end tests are slow and cover broad flows. Google's guidance says unit test coverage is only a piece of the puzzle and integration and system coverage matter too, so merge reports from each level rather than reading one in isolation.
What coverage target should you set?
There is no universal number. Google offers general guidelines of 60% as acceptable, 75% as commendable and 90% as exemplary, and says it prefers to avoid top-down mandates and lets each team choose a value that fits its business. Atlassian's guide says 80% is generally accepted as a good goal, and suggests a lower failure threshold (for example 70%) as a safety net.
Useful ways to set the target:
- Gate on new or changed code, not the whole repo. Google notes that project-wide goals above 90% are probably not worth chasing, while per-commit goals are reasonable because they stop tests getting worse over time.
- Gate on the delta: fail a pull request that lowers coverage instead of setting a fixed floor.
- Raise the bar on critical paths. Payments, auth and data deletion deserve more scrutiny than glue code.
- Exclude generated code, type definitions and configuration so they do not inflate or dilute the number.
Google's blog also cautions against treating a threshold as a checkbox: pressure to hit the metric almost never produces the behavior you wanted.
How do requirement and scenario coverage fit in?
Structural coverage looks at the code you wrote. It cannot tell you about behavior nobody implemented or nobody wrote a test for. Requirement coverage works from the other direction: list the behaviors you promised (user stories, acceptance criteria, scenarios) and count how many have at least one test.
A simple version: keep scenarios in a Markdown file per feature, give each an ID, and tag tests with the ID they verify. A script, or a tool, can then report scenarios with no tests. See acceptance test examples for scenario formats and spec-driven testing for the workflow.
Requirement coverage is the metric that answers "what should we test next?" Code coverage can say a file is 40% covered, but it cannot say whether the 60% you skipped matters to users.
Which coverage metrics should a small team track?
A short set beats a long dashboard. For a team of 10 to 50 engineers with little or no dedicated QA, a workable starting list is:
- Branch coverage on changed code as a pull request check, with a floor you picked together.
- Mutation score on the three or four modules where bugs cost the most, run nightly.
- Scenario coverage: the share of documented scenarios with a passing test.
- Real-usage coverage: which user paths happen in production that no test touches.
The first two describe the code. The last two describe whether the tests match what users do.
How do you keep coverage metrics honest when agents write tests?
Agents raise the volume of tests, and so they raise the risk that the numbers look good while the checking is thin. A few habits help:
- Review assertions, not just line counts. A test with no
expectcall should fail review. - Run mutation testing on agent-written tests for risky modules.
- Treat a jump in coverage with no matching jump in killed mutants as a warning sign.
- Keep a scenario list that a person owns, so the agent has something concrete to test against.
TestChimp keeps scenarios as Markdown in your repo, links Playwright tests to them, and shows scenarios with no test, so the gap view does not depend on reading a coverage percentage. TrueCoverage, available on the Growth plan or during the trial, compares what real users do against what your tests exercise.
Frequently asked questions
What are the main test coverage metrics?
The common structural metrics are statement, line, branch and function coverage. Beyond those, mutation score measures whether tests detect injected faults, and requirement or scenario coverage measures how much specified behavior has a test.
What is the difference between line coverage and branch coverage?
Line coverage counts lines that ran. Branch coverage counts each true and false outcome of a decision. A function with one if statement can have full line coverage and only half its branches covered.
How much test coverage is enough?
There is no universal figure. Google offers 60% as acceptable, 75% as commendable and 90% as exemplary, and lets teams choose their own value. Gating new code and critical paths works better than one repo-wide mandate.
Does 100% code coverage mean no bugs?
No. Coverage shows that code ran during tests, not that the tests checked the results. A test with no assertions can reach full coverage and still catch nothing.
What is mutation score?
Mutation score is the percentage of deliberately injected code changes (mutants) that cause at least one test to fail. A low score means tests run the code without verifying its behavior.
Can Playwright measure code coverage?
Yes, for JavaScript and CSS through page.coverage, but the Playwright docs state the coverage APIs are supported only on Chromium-based browsers. Data can be converted to an Istanbul report with v8-to-istanbul.
See the scenarios no test covers
Link Playwright tests to scenarios in your repo and find the gaps coverage percentages hide. 14-day free trial, no credit card.