On this page
Test coverage is the share of a software system that its tests exercise, measured against requirements and scenarios or, as code coverage, against the lines, branches and functions that run during the test suite. It is reported as a percentage. A high number means much of the code ran, not that the tests check the right things.
This guide covers what test coverage means, how it differs from code coverage, the formulas, how much coverage is enough, how unit and integration tests contribute, and how to find the untested code that matters most.
What is test coverage?
Test coverage answers one question: how much of what we built do our tests touch? In software testing the term is used at two levels, and most confusion comes from mixing them.
- Test coverage in the broad sense counts requirements, user stories, features or scenarios that have at least one test. A QA team tracking whether every acceptance criterion has a test case is measuring test coverage this way.
- Code coverage counts the code itself: which lines, branches and functions executed while the tests ran. A tool instruments the program, runs the suite and reports the percentage. When developers say "our coverage is 82%", they almost always mean code coverage.
Both are useful, and neither measures test quality. A test that calls a function and asserts nothing still counts as coverage. Martin Fowler's summary is that coverage is "a useful tool for finding untested parts of a codebase" and "of little use as a numeric statement of how good your tests are" (Test Coverage).
Test coverage vs code coverage
Code coverage is one way to measure test coverage: the automated, code-level one. Test coverage is the wider idea and can include things no instrument measures, such as whether a business rule has a test case at all.
| Test coverage | Code coverage | |
|---|---|---|
| What it counts | Requirements, features, scenarios, risks with tests | Lines, branches, statements, functions executed by tests |
| Measured by | Traceability matrices, test management tools, review | Instrumentation tools: coverage.py, Istanbul/nyc, JaCoCo, go test -cover |
| Who usually owns it | QA, product, test leads | Developers, CI |
| Automated | Partly | Fully |
| Blind spot | Says a test exists, not that it runs every path | Says code ran, not that the test checked the result |
Scroll the table sideways to see every column.
Test coverage formula
Every coverage formula has the same shape: covered items divided by total items, times 100. What changes is the item.
| Type | Formula | What it misses |
|---|---|---|
| Requirements coverage | requirements with at least one test / total requirements x 100 | Whether those tests run every path |
| Line (statement) coverage | lines executed / executable lines x 100 | Branches inside a line, such as a short-circuited condition |
| Branch coverage | branches taken / total branches x 100 | Combinations of conditions |
| Function coverage | functions called / total functions x 100 | Everything inside the function after the first line |
| Condition coverage | boolean sub-conditions evaluated both true and false / total sub-conditions x 100 | Combinations across conditions |
Scroll the table sideways to see every column.
A worked example. A file has 200 executable lines and 40 branches. The test suite runs 170 of the lines and takes 26 of the branches:
line coverage = 170 / 200 x 100 = 85%
branch coverage = 26 / 40 x 100 = 65%
Branch coverage is usually lower and more honest, because a line like if user and user.is_admin: counts as covered when it runs once, even if the is_admin branch never does. Most tools report both; coverage.py needs --branch to measure branches.
pytest --cov=src --cov-branch --cov-report=term-missing # Python, line and branch
npx vitest run --coverage # JavaScript/TypeScript
go test -coverprofile=cover.out ./... && go tool cover -func=cover.out
How much test coverage is enough?
There is no single right number, but published guidance clusters around 70 to 90% for a project, and much higher for new code. Google's testing blog gives the most cited figures: "at Google we offer the general guidelines of 60% as 'acceptable', 75% as 'commendable' and 90% as 'exemplary'", and adds that "per-commit coverage goals of 99% are reasonable, and 90% is a good lower threshold" (Code Coverage Best Practices, August 2020). Fowler expects "a coverage percentage in the upper 80s or 90s" from thoughtful testing and would be "suspicious of anything like 100%".
Three rules follow from that guidance:
- Gate the change, not the total. A legacy codebase at 40% cannot jump to 80%, but every pull request can be held to a high bar on the lines it adds. That is patch coverage: of the changed lines a report marks executable, the share the tests ran.
- Cover what changes. Google's post says to "make sure that frequently changing code is covered". Untested code that nobody edits costs little; untested code that changes weekly is where regressions come from.
- Do not chase 100%. The last few percent are usually error handlers, generated code and defensive branches that cost more to test than they protect. Google's post notes that gains past a certain point are logarithmic.
Is 100% code coverage worth it? Rarely as a project target. It is reasonable for small, critical libraries (a parser, a crypto wrapper) and as a target for new code in a pull request. As a codebase-wide mandate it tends to produce tests written to execute lines, not to check behavior.
Unit vs integration tests: what each covers
Unit tests cover the logic inside one function or class in isolation; integration tests cover how several parts work together, including real databases, queues or HTTP calls. Both add to code coverage, but they catch different bugs.
| Unit test | Integration test | |
|---|---|---|
| Scope | One function, class or module | Several modules, often with real infrastructure |
| Dependencies | Replaced with fakes or mocks | Real, or close to real (a test database, a local server) |
| Speed | Milliseconds | Seconds or more |
| Finds | Logic errors, edge cases, wrong calculations | Wrong contracts between modules, bad queries, configuration errors |
| Coverage it produces | Deep, narrow | Broad, shallow |
Scroll the table sideways to see every column.
Both matter because real bugs split across the two columns: in our study of the most common coding errors, wrong-result bugs (logic, parsing, state and similar) were 41.69% of bug fixes that name a cause (averaged per repository), and integration and environment bugs 24.43%. A high number made only of unit tests with heavy mocking can miss every integration bug, because the mocks encode what the author assumed the other side does. A suite of only integration tests covers lots of lines but rarely the edge cases. Most teams aim for many unit tests and fewer integration tests, plus a handful of end-to-end tests on the critical paths.
How much test code do real projects keep? We analysed 195 popular open-source repositories (1,000+ GitHub stars each, November 2026). 188 of them (96%) contain test files. The median repo has 0.52 test files per production file, and 28 repos (14%) have more test files than production files; apache/airflow has 4,158 test files for 4,387 production files. It varies by language:
| Primary language | Repos | Median test files per production file |
|---|---|---|
| JavaScript | 13 | 0.77 |
| Python | 51 | 0.70 |
| Go | 22 | 0.58 |
| TypeScript | 52 | 0.52 |
| C# | 10 | 0.24 |
| Rust | 15 | 0.19 |
| C++ | 8 | 0.13 |
Scroll the table sideways to see every column.
Rust's low ratio is partly structural: Rust unit tests usually live in a #[cfg(test)] module inside the production file, so they do not show up as separate test files. Groups under 15 repos are small; read those rows as indicative.
Coverage without a coverage run: which files have no tests?
You can tell which files no test reaches without running the suite, by following the call and import graph from the tests. If no test file calls into a module, directly or through a chain of imports, that module has no test coverage, whatever the coverage report from three months ago says.
repowise does this from its index. Every answer is labelled measured (from an ingested coverage report) or inferred (from the graph), and the two are never averaged. An inferred answer says which test files reach a file; it never invents a percentage. On a slice of the repowise repository checked against real per-test coverage, the inferred list of tests to run for a change was 97.5% precise.
# 1. Produce a report in any common format (LCOV, Cobertura, Clover, JaCoCo, Go coverprofile, .coverage)
pytest --cov --cov-report=lcov:coverage.lcov
# 2. Ingest it, then read the results
repowise coverage add coverage.lcov
repowise health # untested hotspots appear in Fix first
repowise impacted-tests main...HEAD # the tests that guard this branch
# 3. Gate a pull request on patch coverage (needs only git and a report)
repowise coverage check origin/main...HEAD --report coverage.lcov --fail-under 80
repowise coverage check exits 1 when the changed lines fall below the gate, and a file missing from the report is listed as not_in_report, never counted as 0%. With an index, each uncovered range names the test file to extend.

See it on a real repository on the FastAPI Tests page, and read the test coverage feature page for the formats and CI setup. To compare coverage tools themselves, see the best test coverage tools.
Test the risky code first: untested hotspots
Write the next test for the file that changes most, is depended on most and is covered least. A coverage percentage tells you how much ran; it does not tell you which gap is dangerous. If the suite itself is the slow part, profile it with pytest --durations and py-spy before you add more tests.
repowise flags a file as an untested_hotspot when it is all three:
| Condition | Threshold |
|---|---|
| A hotspot | Top-quartile recency-weighted churn in the repository, plus absolute activity floors |
| Depended on | At least 4 dependents |
| Under-tested | Line coverage below 40%; with no report, only when nothing (no paired test file, no test reaching it in the graph) touches it |
Scroll the table sideways to see every column.
Those files are where a missing test costs the most, because every change to them is likely and every break reaches several other files. The full method, including the CRAP score for ranking functions by complexity and coverage together, is in untested hotspots: what to test first. The glossary entry on test coverage gaps has the short definition.
FAQ
- What is meant by test coverage?
- Test coverage is the extent to which tests exercise a software system, expressed as a percentage. In the broad sense it counts requirements or scenarios that have tests; measured as code coverage, it counts the lines, branches and functions that ran during the test suite.
- How much test coverage is enough?
- Most teams aim for roughly 70 to 90% across a project and a higher bar on new code. Google's published guideline calls 60% acceptable, 75% commendable and 90% exemplary, and treats per-commit goals of 99% as reasonable. Gating each pull request on patch coverage works better than one global target.
- Is 100% code coverage worth it?
- Usually not as a project-wide target. The last few percent are mostly error paths and defensive code that are expensive to test, and a hard 100% mandate encourages tests that run lines without checking results. It can make sense for small, critical libraries and for the lines a pull request adds.
- What is the difference between code coverage and test coverage?
- Code coverage is measured by a tool that instruments the code and records which lines, branches and functions ran during the tests. Test coverage is the broader idea of how much of the system's requirements, features and risks have tests at all. Code coverage is one automated way to measure test coverage.
- What is patch coverage?
- Patch coverage is the share of lines changed in a pull request that the tests executed, out of the changed lines a coverage report marks executable. It judges only new and modified code, so a team can hold every change to a high bar even when the codebase's overall coverage is low.
- What is the test coverage formula?
- Test coverage = (covered items / total items) x 100. The item depends on the type: requirements with tests for requirements coverage, executed lines for line coverage, taken branches for branch coverage, and called functions for function coverage.



