What to test and why · mid
Test coverage: what it means and what it does not
Coverage reports which lines, branches, functions and statements ran during tests, which shows untested code but not whether the tests check the right things, so use it as a signal (especially on changed code) and never as the goal.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Kinds: statement, line, function and branch coverage. Branch coverage (both sides of every if, ?:, &&, ||) is the most useful of the four.
- Tools: Istanbul instrumentation (Jest default) or V8's built-in coverage (Vitest default, Jest option, Node --experimental-test-coverage).
- 100% coverage only means every line ran. A test with no assertions still 'covers' code; boundary values and wrong logic can still be untested.
- Mutation testing (for example Stryker) changes your code (> to >=, true to false) and checks that a test fails; it measures test quality better than coverage.
- Useful practice: require coverage on changed lines in PRs (diff coverage) and look at uncovered branches in risky code (payments, permissions), instead of a global 90% target that leads to useless tests.
The red pen
Common traps: mistake → fix
Mistake: "100% coverage means no bugs"
Fix: it means every line ran, not that the results were checked or the edge cases tested.
Mistake: "Set an 80% coverage gate for the whole repo"
Fix: people write assertion-free tests to hit the number; target risky and changed code.
Mistake: "Line coverage and branch coverage are the same"
Fix: one line can contain two branches, and only one may be tested.
Easy to hard
Questions interviewers ask, easy to hard
- What does test coverage measure?
- Is 100% coverage a good goal? Why or why not?
- What is mutation testing?
- How would you use coverage data in code review?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.