Guide
Code coverage vs test coverage: what each one tells you
By the CoverOps team · Last updated
Short answer
Code coverage is a measurement: the share of lines, branches or methods that executed while tests ran. Test coverage is a judgement: whether the requirements, risks and user journeys that matter have tests. Code coverage can show where test coverage is missing, but a high code-coverage number does not prove the tests are good.
Code coverage: what ran
Instrumentation records which code executed while a test suite ran. It is usually reported as line, branch or method coverage. It is objective and cheap to collect, and it answers one question precisely: did any test make this code run?
Most teams only collect it for unit tests, inside the build. Their end-to-end, API and manual tests, which take most of the regression time, run against deployed services where nobody measures. Measuring there is what runtime coverage tools, including CoverOps, are for.
Test coverage: what is tested
Test coverage is about intent: is there a test for each requirement, each risky path, each important journey? It is assessed against a list (requirements, user stories, risks) rather than measured from execution.
How they relate
- Code that never ran is untested, for certain. That is the most useful thing code coverage says: a red line is a gap in test coverage, with no interpretation needed.
- Code that ran is not necessarily tested. A test can execute a line and assert nothing about its result. Research on real projects found that coverage is not strongly correlated with how many faults a suite detects once suite size is accounted for (Inozemtseva and Holmes, 2014).
- Linking the two needs attribution. Knowing that a requirement's tests ran the code a change touched requires coverage per test, not only per suite.
Using both without fooling yourself
- Use code coverage to find what your tests never reach, and to check that a change was exercised.
- Measure the coverage of changed lines, not the repository total, which barely moves either way.
- Do not set a coverage target as a quality goal; teams meet it with tests that execute code without checking it.
- Pair coverage with review of what the tests assert, for the paths that matter most.