All jobs / Full-stack developer / Testing
Full-stack developer interview question · 1–3 years
Your service runs a query with a join and a couple of filters, and the team is arguing about how to test it.
Do you test this against a real database or against a mocked repository?
The strongest answer
Against a real instance of the same engine, started for the test run and thrown away — a mocked repository only proves your own assumptions, never that the query returns the right rows
Why it works
Right — same engine, disposable instance. Joins, constraints, types and migrations are exactly what this test should exercise.
What a good answer covers
- Test queries against the real engine.
- Start it per run; throw it away.
- Substitutes hide dialect bugs.
- Never point tests at shared data.
Answers that fall short
- Close, but not the strongest: Against an in-memory or file-based substitute, so the test still runs SQL without needing a database in CI
Closer, but a different engine has different SQL, different types and different constraint behaviour, and the bug you are hunting hides in that gap. - Weak: Mock the repository and assert that the service called it with the expected filter object
That test passes when the query returns nothing and fails when you refactor: it asserts the mock, not the behaviour. - Red flag: Point the test at the shared development database; it already has realistic data in it
Tests that write into a shared database corrupt other people’s work and pass or fail depending on who ran what first.
Who gets asked this
More Testing questions
- How do you test the parts that are not a request — an incoming webhook and a nightly job?
- Someone deleted a required field and merged because the unit tests still passed. What should CI do?
- The end-to-end suite passes alone and fails when it runs in parallel. What is wrong with the test data, and…
- How do you stop the API from breaking the UI in CI?
- Where should the end-to-end suite run in CI — against shared staging, or against a stack built for the run?
- What would you run against production itself, and what must such a check never do?
- You inherit a slow, flaky suite the team has learned to ignore. What is your strategy for the next quarter?
- You built a feature that touches a React screen and two API endpoints. Which tests do you write, and where?