Code coverage measures how much code a test suite executes. It usually means line coverage: the percentage of statements run during testing. The number is useful for tracking testing effort, but it does not say whether tests check the right result. Even 100% line coverage can leave important behavior or edge cases untested. section 5.1.2
Two measures reveal different gaps:
- Line coverage asks whether each statement ran. It can be complete even when a test exercises only one outcome of a condition. section 5.1.3
- Branch coverage asks whether tests took both the true and false outcomes of conditions, including those in loops. Use it alongside line coverage to spot paths worth testing. section 5.1.3
public int getNameLength(boolean isCoolUser) {
User user = null;
if (isCoolUser) {
user = new John();
}
return user.getName().length();
}
A test with `isCoolUser` set to true executes every statement, giving 100% line coverage. With it set to false, `user` stays null and the return statement throws a null pointer exception. Branch coverage exposes the missing false outcome: the single test covers only 50% of branches. section 5.1.3
Track coverage, but resist treating a fixed percentage as a release gate. An 80% target can encourage tests written to satisfy the number rather than improve confidence. Review whether tests validate behavior, cover meaningful cases, and remain readable and maintainable. Green tests and a high coverage figure are not substitutes for those checks. section 5.1.2 section 5.6
Coverage also depends on which cases people thought to write. Property-based testing offers a complementary approach: define a general rule and generate many inputs that may reveal overlooked edge cases. For a proof of concept, keep enough tests to check correctness, even if testing effort is lighter; it may need to move into production sooner than expected. section 5.1.3 section 5.3.9





















