Code coverage is a measurement of how much of your source code runs while the automated test suite executes. It is usually reported as a percentage of lines, branches (each side of an if) or functions that were hit, by tools such as coverage.py, JaCoCo and Istanbul.
Why it matters
Coverage reveals code that no test touches, which is a good place to look for missing tests. Teams often track it in CI and fail a build when it drops. However, coverage measures execution, not correctness. A test can run a line without asserting anything about its result, so high coverage does not prove the code is right, and chasing 100 percent can produce low-value tests. Branch coverage is stricter and more informative than line coverage.
Example
def grade(score):
if score >= 50:
return "pass"
return "fail"
def test_pass():
assert grade(80) == "pass"
This test gives about 75 percent line coverage and misses the fail branch. Adding assert grade(10) == "fail" brings it to full coverage.
Common mistakes
- Treating a coverage number as a quality score.
- Writing assertion-free tests just to raise the figure.
- Ignoring uncovered error-handling paths, where bugs often hide.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.