Testing a feature and estimating work · core
Test layers, real databases and flaky tests
A good test plan puts most value in integration tests against a real database, keeps unit tests for logic, adds a few end-to-end journeys and contract checks, and treats flaky tests as bugs.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Unit: pure logic with many cases (pricing, state machines, validation), fast. Integration: the service with a real database, real migrations and real SQL, with downstream services stubbed at the network (WireMock or similar).
- Contract tests (Pact consumer-driven contracts, or OpenAPI checks) break CI before a change breaks staging. A can-I-deploy check helps. End to end: a few critical journeys, because they are slow and flaky. Load: before big launches.
- Coverage is not quality: mocking everything gives false comfort, while real bugs live in SQL, wiring, config and timeouts.
- H2 or SQLite differ from production in SQL dialect, types (jsonb, arrays, enums), constraints, locking and ON CONFLICT. Tests pass and production fails. Use the same major database version in a container (Testcontainers) with the real migrations.
- Mocks are right for pure logic and for forcing rare failures (a timeout, a deadlock error), not as proof that a query works.
- Speed: one container per test run, a template database or a rolled-back transaction per test, parallel tests on separate schemas.
- Flaky tests: measure with CI history; run suspects in a loop. Causes: shared state, an unordered query, fixed sleeps, real time and time zones, random data, real third-party sandboxes, containers not ready, port clashes.
- Quarantine a flaky test with an owner and a ticket; do not delete or ignore it. Retries are a signal that reports flakiness, never the fix. Fix with unique data per test, polling assertions, a fixed clock and stubbed partners.
The red pen
Common traps: mistake → fix
Mistake: High coverage means good tests
Fix: check that tests catch real bugs and use a real database.
Mistake: In-memory databases are close enough
Fix: dialect, types and locking differ.
Mistake: Automatic retries fix flaky tests
Fix: they only hide them.
Easy to hard
Questions interviewers ask, easy to hard
- What do you unit test, integration test and end-to-end test in a service?
- Should you mock the database in tests?
- Your integration tests fail one run in ten in CI. What do you do?
- You have one week to add tests to an untested service. Where do you start?
Practise
Practise with these questions
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.