What Is Code Coverage in Testing?
Code coverage measures the percentage of a codebase's lines, branches, or functions that are executed while running a test suite.
Published November 15, 2026
Code coverage measures what percentage of your code is executed by your tests (lines, branches, functions). It shows what is untested but does not prove the tests are good.
The concept
Line coverage counts executed lines; branch coverage checks each if/else path; function coverage counts called functions.
100% coverage can still miss bugs if tests do not assert anything meaningful. Use it to find untested areas, not as a goal in itself.
Coverage report
npx jest --coverage
File | % Stmts | % Branch | % Lines
cart.js | 92.3 | 75.0 | 92.3
pay.js | 40.0 | 20.0 | 40.0 ← needs tests
Practical examples
Jest threshold
{ "jest": { "coverageThreshold": { "global": { "branches": 80, "lines": 85 } } } }Python
pytest --cov=app --cov-report=term-missingPHP
vendor/bin/phpunit --coverage-textCommon mistakes
- Chasing 100% with assertion-free tests.
- Ignoring branch coverage.
- Excluding important code to hit a number.
Key takeaways
- Measures executed code, not correctness.
- Branch coverage is more informative than lines.
- Use it to find gaps.
FAQ
What is a good target?
Many teams aim for 70–90% on important code.
What is mutation testing?
It changes code to check whether tests fail, measuring test quality.