Code coverage measures the fraction of existing code executed by automated tests. JaCoCo instruments Java bytecode and reports coverage by lines, bytecode instructions, or branches. section 1.4
Treat coverage as a test-quality signal, not proof of correctness. Coverage above 80% generally becomes increasingly expensive, some statements are unreachable, and even 100% coverage does not show that the program is bug-free. section 1.4 section 1.8
Use coverage reports to:
- Inspect whether conditional branches have tests, especially in series of if-else conditions. section 3.2
- Add tests for uncovered branches, while recognizing that some defensive statements cannot be reached. section 1.4 section 3.2
- Combine coverage with unit tests, static analysis, code reviews, dynamic analysis, and mutation coverage rather than relying on one metric. section 1.8
A passing test is not comprehensive coverage
A test that calls average(0, 10) once exercises the method, but the single passing case does not establish that every relevant behavior is tested. Coverage records execution; test assertions still determine what correctness is checked. section 1.4
class MyObject implements Cloneable {
public MyObject clone() {
try {
return (MyObject) super.clone();
} catch (CloneNotSupportedException e) {
// never happens as we implement Cloneable
throw new AssertionError(e);
}
}
}
Use the Cloneable example to see why a required catch-body statement may remain uncovered even though the exception is not expected to occur. section 1.4













