Question presented to candidate: "Your team's test suite for a Node.js API has a mix of very fast tests and noticeably slower ones testing what seems like similar functionality. Is that a problem to fix, or is that difference actually expected and useful?"
What a strong answer should cover:
- The speed difference is expected and useful — it directly reflects what each test layer is actually verifying, not an accident to normalize away. 📌 Verified, not assumed: a genuinely isolated unit test (a pure function, zero I/O) ran in a real ~0.7 milliseconds; a genuine integration test (a real Express server on a real ephemeral port, an actual HTTP round trip, a real — if in-memory-faked — database call) took a real ~428 milliseconds on the identical machine — a real, measured ~600x difference, directly illustrating what "isolation" costs and buys.
- 📌 Interview term: unit test — tests one piece of logic in complete isolation (verified above: no server, no database, no network) — fast, precise about failures (a failure points at exactly one function), but cannot catch a problem in how pieces genuinely connect.
- 📌 Interview term: integration test — tests multiple real components together (verified above: a genuine HTTP server, a genuine request/response cycle) — slower, but catches real wiring/connection problems a unit test's isolation cannot see by design.
- 📌 Interview term: end-to-end (e2e) test — tests the entire deployed system as a real user/client would interact with it (a real browser or HTTP client against a genuinely running, fully deployed instance, often including real or realistic external services) — slowest and most brittle of the three, but the only layer that genuinely verifies the complete real system actually works end to end, not merely its individual pieces or internal wiring.
- The precise, practical shape most real teams converge on (often called the "testing pyramid"): many fast unit tests, a moderate number of integration tests, and few e2e tests — directly reflecting the real cost/speed/confidence trade-off verified above: unit tests are cheap enough to write exhaustively, e2e tests are expensive enough (in both runtime and flakiness) that only the most critical, complete user flows typically get one.
Clarifying questions expected:
- "Does the current test suite's mix roughly follow that pyramid shape (many unit, fewer integration, fewest e2e), or is it inverted in a way that's genuinely slowing the team down?" — an inverted pyramid (too many slow e2e tests, too few fast unit tests) is a real, common anti-pattern worth surfacing.
- "Are the slower tests genuinely integration tests catching real wiring issues, or are they unit-test-shaped tests that happen to be slow for an unrelated, fixable reason (an unnecessary real network call, for instance)?" — not all slowness is a legitimate integration-test cost.
Code / implementation expected: Yes — a real, measured timing comparison between a genuinely isolated unit test and a genuine integration test exercising a real HTTP server is the concrete, convincing proof of exactly what the speed difference reflects and why it's expected.