QA Metrics
Code Coverage
A metric measuring what percentage of code is executed by automated tests.
Full definition
Code coverage is a metric that measures the percentage of source code executed during automated testing. It helps identify untested areas but should not be the sole quality indicator.
Coverage types:
- Line/Statement coverage: % of lines executed
- Branch coverage: % of if/else branches taken
- Function coverage: % of functions called
- Condition coverage: % of boolean conditions tested both true/false
Common targets:
- 80%+ statement coverage is a reasonable goal
- 70%+ branch coverage
- Critical paths should have near-100% coverage
Important caveats:
- 100% coverage ≠ zero bugs (you can execute code without meaningful assertions)
- Coverage measures quantity, not quality of tests
- Chasing coverage numbers can lead to low-value tests
- Some code is hard to test (error handlers, race conditions)
Tools: Istanbul/nyc (JavaScript), JaCoCo (Java), coverage.py (Python), dotCover (.NET)
Use coverage to find gaps, not as a target. 'We have 90% coverage' means nothing if the tests don't assert meaningful behavior.