What is test coverage and what are the risks of over-relying on it?
Answer
Test coverage measures what percentage of code is executed by tests — a useful indicator for finding untested code. Types: statement, branch, function, path coverage. Risks of over-relying on coverage metrics: (1) Coverage ≠ quality: assertTrue(true) increases coverage but tests nothing meaningful. 100% coverage with meaningless assertions is worthless. (2) Goodhart's Law: "When a measure becomes a target, it ceases to be a good measure." Teams game the metric by writing tests that cover code without asserting correct behavior. (3) Missing edge cases: 100% line coverage doesn't mean all branches, values, or edge cases are tested. (4) False confidence: high coverage can make teams complacent. (5) Wrong incentives: chasing coverage leads to testing implementation details instead of behavior, making tests brittle to refactoring. Healthy use: track coverage to identify gaps (areas with zero coverage are risky); don't use arbitrary thresholds as goals. Combine with mutation testing for quality assessment.