Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

Your organisation's test suites have high coverage but production defects remain frequent and refactors break hundreds of tests. What test standards would you introduce?

High coverage with frequent defects and brittle tests means the suites check how code is written rather than what it does. I would shift from interaction-heavy mocks to behaviour tests at service boundaries, use real or fake collaborators inside a module and mocks only at external boundaries, test data access against real infrastructure, review tests as carefully as production code, measure test value with mutation testing, and track escaped defects per area to see where the tests are weak.

Why this question is asked

Coverage is the most visible test metric, so it is often the one organisations manage. This scenario describes what happens when that goes wrong: 85 percent coverage, a dashboard full of green, and still incidents every week and refactors that turn hundreds of tests red. Interviewers ask it to see whether we can diagnose a systemic problem and change incentives, not just write better tests ourselves. In this answer, we will understand why coverage misleads, diagnose what kind of tests produce these symptoms, and then build the standards one by one, with the reasoning and the measurement that keeps them honest.

1Why Coverage Can Be High While Tests Are Weak

Line coverage measures which lines ran during the tests. It says nothing about whether any test would notice if those lines were wrong. A test that calls a method and verifies that its mocks were called, but asserts nothing about the result, covers every line and checks almost nothing.

Here is a small example. The test below gives 100 percent coverage of applyDiscount(), yet if someone changed 0.9 to 0.8, or removed the if, it would still pass.

Java
BigDecimal applyDiscount(Customer c, BigDecimal price) {
if (c.isGold()) return price.multiply(new BigDecimal("0.9"));
return price;
}
@Test void discount() {
Customer c = mock(Customer.class);
when(c.isGold()).thenReturn(true);
service.applyDiscount(c, new BigDecimal("100")); // 100 percent line coverage
verify(c).isGold(); // no assertion on the price
}

So the two symptoms in the question are connected. Tests built around mocked interactions break when the interactions change, which is every refactor, and they catch few defects, because they rarely check results against real collaborators.

2Diagnosing the Suite Before Changing It

Before writing standards, I would gather evidence, because teams resist rules that feel imposed. Three measurements give a clear picture in a few weeks. First, mutation testing with a tool such as PIT on a few representative modules: it makes small changes to the code, such as flipping a condition or changing a constant, and reports how many of those mutants the tests kill. Coverage of 85 percent with a mutation score of 40 percent is a convincing story. Second, the last few months of production defects, classified by area and by the kind of test that should have caught them. Third, a count of tests broken by recent refactors that did not change behaviour.

Typical findings are that most escaped defects involve SQL, mapping, serialisation or integration between services, the very places that mocks replaced, and that the tests broken by refactors are dominated by verify() lines.

What the evidence usually shows
MeasureExample valueWhat it means
Line coverage85 percentcode runs during tests
Mutation score (PIT)40 percentmost wrong code would still pass
Escaped defects in data access45 percent of incidentsmocked repositories hide SQL bugs
Tests broken by a pure refactor300 for one PRtests mirror implementation

3Standard 1: Behaviour Tests at Service Boundaries

The first standard changes the unit of testing. Instead of one test class per Java class with every collaborator mocked, we test a service through its public entry point, such as an application service method or an HTTP endpoint, and assert on what comes out: the response, the stored state, the published event. The internal classes are used for real.

The reason is that the public boundary changes much less often than the classes behind it. A refactor that splits a class in two leaves the boundary unchanged, so the behaviour tests keep passing, which is exactly what we want from a refactor.

4Standard 2: Real or Fake Inside, Mocks Only at External Boundaries

Inside a module, collaborators should be real objects or fakes. A fake is a simple working implementation, such as a repository backed by a map, or a clock fixed to a given instant. Mocks are reserved for external boundaries we do not control or cannot run cheaply: a payment provider, an email service, a partner API.

Data access gets its own rule: repositories and queries are tested against a real database with Testcontainers, typically in a @DataJpaTest or @JdbcTest slice. That directly targets the largest group of escaped defects, because SQL, mappings and constraints are exercised for real.

Java
// Behaviour test at the service boundary: real logic, fake store, one boundary mock
var payments = mock(PaymentProvider.class);
var service = new CheckoutService(new InMemoryOrders(), new PriceRules(), payments, Clock.fixed(T0, UTC));
Receipt r = service.checkout(cart("SKU-1", 2, "50.00"), goldCustomer());
assertEquals(new BigDecimal("90.00"), r.total()); // 2 x 50 with a 10 percent gold discount
verify(payments).charge(any(), eq(new BigDecimal("90.00"))); // the external effect
Step throughTest standards by layer
  1. End-to-enda few journeys in a shared environment
  2. Service boundary testsreal internals, fakes, mocks only for external APIs
  3. Data access tests@DataJpaTest with Testcontainers, real SQL
  4. Pure logic testsplain objects, no doubles

4 layers, from the top down. Step through them one at a time.

5Standard 3: Review Tests and Measure Their Value

Tests are code that decides whether we ship, so they get the same review as production code. Reviewers ask one question for every new test: which bug would make this fail? A test that only verifies calls, or asserts nothing, does not get merged.

Coverage stays on the dashboard as a floor, not a target, and mutation score joins it for the critical modules, such as pricing, payments and permissions. We do not run mutation testing on every build of every service, because it is slow; a nightly run on the important modules, or a run on the changed classes in a pull request, is enough to show the trend.

6Standard 4: Track Escaped Defects Per Area

Finally, the feedback loop. Every production defect gets two extra fields in the incident tracker: the area of the code and the kind of test that should have caught it. Reviewed monthly, this shows where the tests are weak, for example 'serialisation between order and billing services, no contract test', and it guides where to invest next.

The rollout follows the evidence. We start with the two or three areas with the most escaped defects, rewrite their worst tests as behaviour and data access tests, and show the before and after numbers: mutation score up, escaped defects down, fewer tests broken by refactors. Success in one area is the best argument for the next. Old tests are changed when they are touched, not in a big-bang rewrite.

Step throughThe improvement loop
  1. Measuremutation score, escaped defects, refactor breakage
  2. Pick the weakest areamost escaped defects
  3. Apply the standards therebehaviour tests, Testcontainers
  4. Compare before and aftershare the numbers
  5. Did defects fall?
    YesExtend to the next areaNoRevisit the standard

5 steps in order. Play them, or step through them one at a time.

7Follow-up questions

Would you drop the coverage target?

I would keep a modest floor, for example 70 percent on new code, to catch untested code, but stop treating higher coverage as success. Mutation score and escaped defects tell us far more about test value.

Isn't testing at service boundaries slower?

Slightly, but with in-memory fakes and no Spring context these tests still run in milliseconds. The Testcontainers tests are slower, so we keep them focused on data access and share containers across the suite.

How do you handle teams that disagree?

With their own data. Running PIT on their module and showing the surviving mutants, or the incidents their tests missed, is more persuasive than any rule, and the standard allows local variation as long as the measurements improve.

8Conclusion

In this answer, we saw that high coverage with frequent defects and brittle tests points to interaction-heavy, mock-everything tests that run the code without checking it. We gathered evidence with mutation testing, escaped defect analysis and refactor breakage, then introduced standards: behaviour tests at service boundaries, real or fake collaborators inside a module with mocks only at external boundaries, real infrastructure for data access, careful test review with mutation testing, and tracking escaped defects per area to guide the next improvement.

What to say in the interviewAbout 80 seconds aloud

Open with

High coverage with frequent defects tells me the tests run the code but do not check it, and refactors breaking hundreds of tests tells me they are coupled to the implementation, usually through mocks and verify calls.

Then, if they want more

Before changing anything I would gather evidence: run mutation testing with PIT on a few modules, classify recent incidents by area and by which test should have caught them, and count tests broken by a pure refactor. Typically the mutation score is far below coverage and many defects are in SQL, mapping and integration, which mocks replaced.

Then I would set four standards. Test behaviour at service boundaries, through the public entry point, asserting on results, stored state and events. Inside a module use real objects or fakes, and mock only external boundaries like payment providers. Test data access against real databases with Testcontainers.

And review tests like production code, asking which bug each test would catch, with mutation score tracked for critical modules and coverage only as a floor. Finally I would track escaped defects per area every month, start with the weakest areas, and show before-and-after numbers to win over the other teams.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Your organisation's test suites have high coverage but production defects remain...": https://scrivio-interview-library.netlify.app/java/mocking/7af02ea7f6/