What Code Coverage Measures
You'll learn what code coverage metrics reveal about how thoroughly your tests exercise your codebase.
Code coverage is a quantitative measure of how much of your source code is executed when your test suite runs. It doesn't tell you if your tests are good, but it does identify which parts of your code are never touched by any test—essentially blind spots in your testing strategy.
The Four Core Metrics
Line Coverage tracks which lines of code were executed. If you have 100 lines and tests ran 80 of them, you have 80% line coverage. This is the most straightforward metric but can be misleading—a line might execute without being meaningfully tested.
Branch Coverage measures whether your tests take both paths through conditional statements. If you have an if/else, did your tests cover both the true and false branches? A function might have 100% line coverage but only 50% branch coverage if you never test the else case.
Function Coverage tracks whether each function in your codebase was called at least once during testing. An uncalled function is completely untested, even if other metrics look decent.
Statement Coverage is similar to line coverage but counts logical statements rather than physical lines. Multiple statements on one line are counted separately.
What Coverage Reveals (and Doesn't)
Coverage metrics show you what ran, not whether it was properly validated. You could achieve 100% coverage by calling every function without a single assertion—technically covered, but practically worthless.
Think of coverage like a map showing which roads you've driven on. It confirms you've been there, but doesn't prove you drove safely or observed anything important along the way.
Key Takeaway: Code coverage identifies untested code paths through line, branch, function, and statement metrics, but high coverage doesn't guarantee quality tests—it only shows what executed.