Branch Coverage
In one line
Branch coverage checks that every if/else branch (both true and false paths) was tested, not just the lines.
In simple words
Branch coverage is stricter than line coverage. It checks not just that a line ran, but that every possible path through conditionals was taken.
For example, consider:
if (x > 0) { return 'positive'; }
return 'non-positive';
If your test only calls this with x=5, the line coverage is 50% (only the first return runs). But even if you test with x=5 and x=-1, getting 100% line coverage, branch coverage checks that you tested both the true path (x > 0) AND the false path (x <= 0).
Branch coverage catches cases where you have 100% line coverage but only tested one side of a condition. It's a more meaningful metric than line coverage alone.
Example
function check(x) {
if (x > 0) return 'positive'; // branch 1: true
return 'non-positive'; // branch 1: false
}
// Test with x=5: covers true branch only (50% branch coverage)
// Test with x=5 and x=-1: covers both branches (100% branch coverage)Branch coverage requires testing both the true and false paths of each conditional.
Related terms
Related Resources
Related Lessons
- Code Coverage
Coverage metrics explained.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.