The 100% Coverage Trap
You'll learn why achieving 100% code coverage doesn't automatically mean your tests are actually good.
The Coverage Illusion
Reaching 100% code coverage feels like victory—every line executed, every branch tested. But coverage metrics only tell you what code ran, not whether your tests actually verify correct behavior. You can execute every line of code with terrible assertions that catch nothing.
Think of coverage like a security camera system. Having cameras in every room (100% coverage) doesn't prevent crime—it only means you could see it if you're actually watching the footage. Similarly, code coverage shows which lines ran during tests, but not whether those tests checked for the right outcomes.
The Problem with Coverage as a Goal
Consider this function with 100% coverage:
function divide(a, b) {
return a / b;
}
// Test with 100% coverage
test('divide function', () => {
divide(10, 2); // Executes the code
expect(true).toBe(true); // Useless assertion
});
Every line ran, but the test verifies nothing. It doesn't check the result, doesn't test division by zero, doesn't validate edge cases. The coverage report shows green, but the code remains untested.
Coverage as a Floor, Not a Ceiling
Coverage metrics serve as a baseline: if a line has 0% coverage, you definitely haven't tested it. But 100% coverage doesn't mean you're done—it means you've started. Good tests require thoughtful assertions, edge case exploration, and real-world scenario validation that coverage numbers can't measure.
Key Takeaway: Use code coverage to identify untested code, not as proof that your tests are sufficient—meaningful assertions and edge case testing matter far more than the coverage percentage.