Code coverage measures which code tests execute, but a high percentage can conceal tests that assert little and contribute little to reliability. section 11.6.1
Use coverage cautiously:
- Treat coverage as a proxy, not a complete measure of software quality. section 11.6.1
- Prefer tests driven by data, domain properties, and meaningful assertions over tests written to exercise physical branches. section 11.6.1
- Build confidence methodically rather than optimizing for an arbitrary coverage threshold. section 11.6.1
Listing 11.58 Asserting the mock responds with what you told it to mock
@Test
void literallyJustHereForCoverage() {
Thing thing = mock(Thing.class); #A
when(thing.getFoo()).thenReturn("Foo"); #A
Service service = new Service(thing);
assertEquals("Foo", service.someMethod()); #B
}A deliberately minimal test demonstrates how coverage can increase without testing meaningful behavior. section 11.6.1





















