Skip to the page

Testing a feature · Trade-off

Unit, integration, contract and load tests for a service

The interviewer asks

For a backend service with a REST API, a Postgres database and two services it calls, how would you split your testing between unit, integration, contract and load tests? Where does most of the effort go?

Then

Follow-ups the interviewer asks next

  1. What do you mean by an integration test for this service?
  2. Why not test everything end to end?
  3. What do contract tests give you that integration tests with stubs don't?
  4. Your team has 85% coverage, but bugs still reach production. Why?
  5. You have one week before launch and almost no tests. What do you write first?
  6. When do load tests run, and against what?
  7. How long should the main test suite take in CI?
  8. In your experience, which kind of test caught the most bugs?

The answer

What a strong answer covers

  • Unit: pure logic with many cases (pricing, state machines, validation); fast.
  • Integration, where much of the value is: the service with a real Postgres (Testcontainers) and its real migrations and SQL, the two downstream services stubbed at the network (WireMock or similar), tested through the API.
  • Contract: consumer-driven contracts (Pact) or OpenAPI schema checks, so a change on either side breaks CI before it breaks staging; a "can I deploy?" check before release.
  • End to end: a few critical journeys in a shared environment. They are slow and flaky, so there are few.
  • Load: before big launches and sales, and on a schedule, with production-like data and limits.
  • Coverage is not quality: mocking everything and testing internals gives false comfort, while real bugs live in SQL, wiring, config and timeouts.
  • One week: integration tests for the money paths and the riskiest queries first, then a contract test for the most-used downstream.
  • CI: the main suite in roughly 10–15 minutes, slower suites on a schedule.

The red pen

Common traps

Avoid:"100% coverage"; mocking the database everywhere; only end-to-end tests.

Practise this out loud

Say your answer out loud to an AI interviewer that follows up, and get a score for it.

Practise by voice

Practise questions like this out loud

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview