Quick revision
The short answer
The main lesson is that a metric used as a target gets optimised for the number rather than for the goal behind it, and coverage is a textbook case. Coverage is a good diagnostic for engineers, showing where tests are missing, but a poor performance target, because it rewards executing code rather than checking it. Outcome measures such as escaped defects, change failure rate and time to recover say much more about quality, and coverage is best used as trends and new-code coverage, discussed in context with the people who own the code.
What to remember
In this answer, we saw that the industry learned, sometimes painfully, that coverage turned into a target gets optimised for itself, producing assertion-free tests and brittle suites without fewer defects. Coverage remains a valuable diagnostic because low coverage reliably shows untested code, but it is a poor performance target. Outcome measures such as escaped defects, change failure rate and time to restore say more about quality, and coverage is best used as trends and new-code coverage, discussed in context with the teams.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The main lesson is that a metric used as a target gets optimised for the number rather than for the goal behind it, and coverage is a textbook case. Coverage is a good diagnostic for engineers, showing where tests are missing, but a poor performance target, because it rewards executing code rather than checking it. Outcome measures such as escaped defects, change failure rate and time to recover say much more about quality, and coverage is best used as trends and new-code coverage, discussed in context with the people who own the code.
Why this question is asked
Most engineering organisations have, at some point, put a coverage percentage on a dashboard and asked teams to raise it. Many have later quietly stopped. Interviewers ask senior candidates about this history to see whether we understand why measures fail when they become targets, and what we would use instead when executives need to see quality. In this answer, we will look at the pattern the industry went through, the principle behind it, what coverage is genuinely good for, which outcome measures replaced it, and how a senior leader uses coverage today.
1The Pattern Organisations Went Through
The story repeats in many companies. Coverage tools became cheap and easy in the 2000s, and coverage numbers became visible on every build. A low number clearly meant missing tests, so leadership set targets: 70 percent, then 80, sometimes a bonus tied to it. For a while the numbers rose and everyone felt better.
Then the side effects appeared. Teams wrote tests for getters and data classes, tests that called methods without assertions, and tests that mocked everything so that a class could be executed in isolation. Suites grew to thousands of tests that broke on every refactoring yet let real defects through. Engineers began to see testing as compliance work. When incidents were analysed, the faulty code was often well covered; it had simply never been checked for the case that failed.
2Why Targets Distort Measures
The principle behind this is often called Goodhart's law: when a measure becomes a target, it ceases to be a good measure. A related idea, Campbell's law, says the more a quantitative indicator is used for decisions, the more it is subject to pressure that distorts it. The reason is simple. A measure is useful when it correlates with what we care about. Coverage correlates with good testing only when people are trying to test well. Once people are rewarded for the number itself, they find the cheapest way to move it, and the cheapest way to move coverage is to execute code without checking it.
Notice that nobody has to act in bad faith for this to happen. An engineer with a deadline and a gate that fails at 79.6 percent will add the test that gets the build green, and that is a rational choice. The system, not the individual, produced the low-value test.
- Coverage is lowa real signal of missing tests
- Leadership sets a targetfor example 80% for every team
- Teams optimise the numbergetters, assertion-free tests, heavy mocks
- Coverage risesthe dashboard looks healthy
- Escaped defects do not fallcovered code still fails in production
- Trust in the metric collapsestesting feels like compliance
6 steps in order. Play them, or step through them one at a time.
The measure stayed the same; the behaviour around it changed.
3What Coverage Is Actually Good For
None of this makes coverage useless. For engineers, it is an excellent diagnostic. A file with 20 percent branch coverage in a payment module is a clear warning, and a coverage view in the IDE shows exactly which paths a new test missed. Uncovered code is definitely untested, so a low number carries real information.
The asymmetry is the lesson: low coverage means something, high coverage means little on its own. So coverage works when engineers use it to ask where they should test next, and fails when managers use it to judge whether teams are doing a good job.
4Outcome Measures That Say More
The industry's answer has been to look at outcomes. The measures popularised by the DORA research programme are widely used: change failure rate (the share of deployments that cause a failure in production), time to restore service, deployment frequency and lead time for changes. Alongside them, escaped defects per release, meaning defects found by customers rather than by our tests, connect directly to what testing is for.
These are harder to game because they measure what happens to customers. They also encourage the right investments. A team with a high change failure rate needs better tests in risky areas, better review or smaller changes; a team that restores service slowly needs better observability and rollback. Coverage cannot tell those situations apart.
| Measure | Good for | Weakness as a target |
|---|---|---|
| Line or branch coverage | Finding untested code | Rewards running code, not checking it |
| New-code coverage | Checking changes come with tests | Still blind to assertion quality |
| Mutation score | Test effectiveness in critical code | Slow; equivalent mutants |
| Escaped defects | Quality seen by customers | Depends on how defects are recorded |
| Change failure rate | Safety of each deployment | Needs a shared definition of failure |
| Time to restore | Resilience and operability | Says little about test gaps |
5How a Senior Leader Uses Coverage Today
In practice I would keep coverage visible, but change how it is read. At the leadership level I report outcomes: escaped defects, change failure rate and time to restore, per product area, as trends over quarters. Coverage appears as context: is coverage on new code consistently above, say, 80 percent, and is the overall trend for critical services flat or rising?
Then the conversation happens with the team. If a service has a rising change failure rate and low coverage in the modules that failed, coverage helps explain the outcome and guides where to invest. If coverage is high and defects still escape, we look at test quality, perhaps with mutation testing on that module. The number is a starting point for a discussion with the people who know the code, never a score on its own.
6Follow-up questions
Is it ever right to set a coverage threshold?
A moderate threshold on new and changed code is a reasonable hygiene rule, because it ensures changes come with some tests without forcing anyone to backfill legacy code for a number. What fails is a high, fixed, organisation-wide target tied to performance evaluation.
Will outcome measures not be gamed as well?
They can be, for example by not recording defects or by redefining what a failure is. That is why definitions must be shared and stable, and why the measures are used for learning rather than for rewards. Any measure tied to individual incentives will be distorted; the goal is to keep measures as information.
How do you convince executives who like a single number?
Show them the gap between coverage and incidents in their own data: a well-covered module that caused an outage, or a coverage jump that did not change defect rates. Then offer two or three outcome measures with a clear trend line. Executives usually want confidence that quality is improving, and outcome trends give that better than a percentage.
7Conclusion
In this answer, we saw that the industry learned, sometimes painfully, that coverage turned into a target gets optimised for itself, producing assertion-free tests and brittle suites without fewer defects. Coverage remains a valuable diagnostic because low coverage reliably shows untested code, but it is a poor performance target. Outcome measures such as escaped defects, change failure rate and time to restore say more about quality, and coverage is best used as trends and new-code coverage, discussed in context with the teams.
Open with
The big lesson is Goodhart's law: once a measure becomes a target, people optimise the number instead of the goal. Coverage is the classic example. When organisations set targets like 80 percent for every team, coverage went up, but through tests of getters, tests without assertions and tests that mock everything.
Then, if they want more
Suites became large and brittle, and incidents kept happening in code that was well covered but never really checked. Nobody acted in bad faith; the incentive produced that behaviour. That does not make coverage useless. It is a very good diagnostic for engineers, because uncovered code is definitely untested, so low coverage is a real signal.
High coverage on its own tells you very little. So for leadership reporting I use outcome measures: escaped defects, change failure rate, time to restore service and lead time, as trends per product area. Coverage stays in the picture as context, mainly coverage on new and changed code and the trend for critical services.
When a team's failure rate rises, we look together at where the failures came from, and coverage helps explain it and guide investment, sometimes with mutation testing in critical modules. I treat it as the start of a conversation with the team, never as a score.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- JUnit user guide, Mockito documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Over many years, what has the industry learned about using code coverage as a management...": https://scrivio-interview-library.netlify.app/java/test-strategy/6f6818d6df/