Code coverage · Comparison
Line, statement and branch coverage
Line coverage asks whether each line ran, statement coverage each statement, branch coverage each decision both ways. Measured examples, and why tools differ.
What is the difference?
Line coverage asks whether each line ran. Branch coverage asks whether each decision went each way. A line can run while one of its branches never does, so 100% line coverage can hide untested paths. Track both. If you enforce one threshold, enforce branches.
A line that ran, a branch that did not
function label(user, fallback = 'Guest') {
return user ? user.name : fallback;
}
One test calls label({ name: 'Ada' }). The return line ran, so line
coverage is 100%. The function never returned fallback, and line coverage
cannot say so. Branch coverage reports one branch missing on that line.
We measured this with Jest 30.5.2 and its default Babel provider, on a file
with this function and one more: 5/5 lines, 6/7 branches. The missing branch
is fallback.
Statement coverage vs branch coverage
Statement coverage asks whether each statement ran. Branch coverage asks
whether each decision went each way. Statement coverage can reach 100% while
a branch never ran: an if with no else runs every statement when its
condition is true, and the false path has no statement to miss.
Statements and lines differ when one line holds several statements:
function double(n) { if (n > 0) { n = n * 2; } return n; }
One test calls double(0). With Jest 30.5.2: lines 2/2, statements 3/4,
branches 1/2. The line ran; the assignment did not; the n > 0 path was
never taken. For decision, condition and path coverage on a larger example,
see Statement vs branch coverage.
Function coverage asks whether each function was called at all. Istanbul-based tools report all four. Many others report lines and branches.
Tools do not count branches the same way
The same three tests on the same JavaScript file:
| Tool | Lines | Branches |
|---|---|---|
| Jest, Babel provider | 5/5 | 6/7 |
| Jest, V8 provider | 14/17 | 4/5 |
node --test, built-in coverage | 14/17 | 5/6 |
All three agree on which branch is missing. They disagree on how many branches and lines exist. Other languages differ again:
- coverage.py counts a branch only when a line can jump to more than one next
line. The Python version of
label, on one line, reported 6/6 lines and 2/2 branches withfallbacknever returned. go test -coverreports statements and has no branch metric.- JaCoCo counts branches in bytecode, where each condition of an
&&is its own jump.
Compare a branch percentage with the same tool’s earlier number, not with another tool’s.
What branch coverage still misses
if (signedIn && !expired) {
Two tests can take this if both ways without ever trying a signed-in
session that has expired. Branch coverage is 100%.
MC/DC is the metric that catches it.
Neither metric says whether a test checked the result. A test can run every branch and assert nothing.
Measure them on your tests
npx supercov -- npm test
npx supercov runs latest gaps
Supercov runs your existing test command and reports line, branch and MC/DC coverage per test, for JavaScript, TypeScript, Python, Go, Java, Kotlin, Rust and Ruby. On the JavaScript file above it reported 7/9 lines, 4/6 branches and 1/3 MC/DC conditions. Assertion coverage then shows which executed statements your tests check, and mutation testing whether they notice small changes.
Example evidence: fixture source, commands and recorded results (JSON). Measured October 12, 2026 with Supercov 4.3.0. These small examples are not a performance benchmark or a general conformance test.