Code Coverage
In one line
Code coverage measures how much of your code is exercised by tests — e.g., '85% of lines were executed during tests.'
In simple words
Code coverage tells you which parts of your code ran during testing and which didn't. It's usually expressed as a percentage: '80% of lines covered' means 80% of your code lines were executed during tests.
There are different types of coverage:
- Line coverage: percentage of lines executed
- Branch coverage: percentage of if/else branches taken (both true and false paths)
- Function coverage: percentage of functions called
- Statement coverage: percentage of statements executed
Coverage is a useful metric but not a guarantee of quality. 100% coverage doesn't mean your code is bug-free — it just means every line ran. You can have 100% coverage with weak assertions that don't actually test anything meaningful. Use coverage as a guide to find untested code, not as a goal in itself.
Example
// Run Jest with coverage
// npx jest --coverage
// Output:
// File | % Stmts | % Branch | % Funcs | % Lines
// math.js | 100% | 85% | 100% | 100%
// utils.js | 80% | 70% | 75% | 82%Coverage report shows different coverage types per file.
Common confusions
Confused with: Test Quality
The difference: Coverage measures which code ran, not whether assertions are meaningful. High coverage with weak assertions gives false confidence.
Related terms
Related Resources
Related Lessons
- Test Coverage
Measuring and interpreting coverage.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.