All jobs / Backend developer / Testing
Backend developer interview question · 1–3 years
Your repository tests run against an in-memory database and pass, but the same query fails in production. What do you change?
The strongest answer
Test against the engine you ship on, in a throwaway container per run — the in-memory substitute has different SQL, types and constraint behaviour — and have each test set up and clean its own data
Why it works
Exactly — same engine, disposable instance, isolated data. Anything else and you are testing a different database.
What a good answer covers
- Test on the engine you ship.
- Disposable instance per run.
- Isolate the data per test.
- In-memory is a different database.
Answers that fall short
- Close, but not the strongest: Run the tests against a real instance of the database so at least the SQL dialect matches
That is the fix; say how it stays reliable — a fresh instance per run and data isolated per test. - Weak: Add a smoke test after deployment that runs the query against production
Finding it in production is late, and it only covers the queries that happen to run; this one was findable in CI. - Red flag: Point everyone at one shared test database and remember to clean up after yourself
A shared database gives you tests that fail depending on who else is running — worse than having no test.
Who gets asked this
More Testing questions
- How do you test that POST /orders returns 201 with the right body, without deploying anything?
- A refactor that changed no behaviour broke forty tests. Each one asserts that a particular method was called…
- What would consumer-driven contract tests give you here?
- The service’s CI suite fails about one run in five for reasons unrelated to the change, and the team’s habit…
- A teammate calls their test a unit test, but it starts a database container and an HTTP server. Does the…
- In a test, what is the difference between a stub, a mock and a fake?