All jobs / Backend developer / Testing
Backend developer interview question · 1–3 years
How do you test that POST /orders returns 201 with the right body, without deploying anything?
The strongest answer
Start the application inside the test process with its real routing, serialisation and middleware, send the request through the framework’s test client, and stub only the external dependencies at the boundary
Why it works
Right — that path covers routing, model binding, validation and serialisation, which is where the status code and the body are actually decided.
What a good answer covers
- Boot the app in the test process.
- Go through routing and middleware.
- Stub only external boundaries.
- Assert status, headers and body.
Answers that fall short
- Close, but not the strongest: Call the controller method directly and assert on the object it returns
That tests your method, not your API: the route, the binding, the status code and the JSON shape are all skipped. - Weak: Run the service locally and point a saved request collection at localhost as part of the build
That works, and it needs a running process and a free port in CI; the in-process client gives the same coverage without either. - Red flag: Test it by hand before each release — automated API tests go stale faster than they catch anything
“It goes stale” is an argument for maintaining the tests, not for shipping a contract nobody checks.
Who gets asked this
More Testing questions
- 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?
- Your repository tests run against an in-memory database and pass, but the same query fails in production…