Testing & QA
Test Coverage (and Its Limits)
The idea, in plain English
Test coverage measures how much of your code your tests actually run. Picture a house inspector: coverage tells you which rooms got walked through, not whether each room passed inspection. If your tests only ever visit the living room, the coverage report shows the bedrooms were never even entered — a strong hint that bugs could hide there. But high coverage isn't proof of quality: you can walk into every room and still not check whether the lights work.
How it works
- 1A coverage tool watches your code while the tests run and marks each line or branch that executed.
- 2It divides the parts that ran by the total parts, giving a percentage — say 80% of branches covered.
- 3The parts never marked are your blind spots: code no test ever exercised.
- 4You use the report to find untested branches, then add tests aimed straight at them.
When you'd use it
Use coverage to find code your tests forgot, especially error branches and rare conditions. Treat it as a flashlight for blind spots, not a grade — chasing 100% for its own sake wastes time on trivial lines while real logic stays weakly checked.
Common beginner mistakes
- Believing 100% coverage means bug-free. Coverage says a line ran, not that you asserted the right thing about it — you can run every line and check nothing meaningful.
- Gaming the number with tests that execute code but assert nothing. The percentage climbs while the safety net stays full of holes.
Try it — edit and run
Click the code to edit · press ⌘/Ctrl+↵ to run
Editable code. Tab and Shift+Tab indent. Press Escape, then Tab, to move focus out of the editor.
Branches hit: positive
Coverage: 33%
Untested branches: negative, zeroNot sure this is the right topic? See the learning paths → or where this leads →