Line Coverage vs Statement Coverage
What you'll learn: You'll understand why "line coverage" and "statement coverage" are often used interchangeably but can actually measure different things in practice.
The Core Difference
Both metrics track how much of your code gets executed during tests, but they count differently:
Line coverage measures which physical lines of your source file are executed. If any part of a line runs, the entire line counts as "covered."
Statement coverage measures which executable statements run. A single line can contain multiple statements, or one statement can span multiple lines.
When They Differ
In many cases, these metrics report identical numbers. But they diverge when:
Multiple statements on one line:
if (x > 0) y = 1; z = 2; // Three statements, one line
If your test only makes x > 0 false, line coverage shows 100% (the line executed), but statement coverage might show 67% (only z = 2 ran, not the condition or y = 1).
One statement across multiple lines:
const result = someLongFunction(
parameter1,
parameter2
);
The tool might count this as three lines but one statement. Executing it covers all three lines but only one statement.
Which Matters More?
Statement coverage is generally more accurate because it reflects logical execution units rather than formatting choices. Two developers might format code differently, changing line counts without changing logic.
However, most modern coverage tools blur this distinction and report values that are effectively interchangeable for well-formatted code.
Key Takeaway: Line coverage counts physical lines executed, while statement coverage counts logical statements executed—they often match but can differ when multiple statements share a line or statements span multiple lines.