Unit test logic with branches and edge cases: pricing rules, parsing, state machines. Integration test the seams where your assumptions meet reality: database queries, serialization, auth middleware, third party clients. If a test needs five mocks to run, it is mostly testing your mocks and the value is in an integration test instead. Aim for many fast unit tests plus a smaller set of integration tests covering the critical paths.
Why interviewers ask this
This is really a question about where bugs come from. The interviewer wants to see that you test behavior rather than implementation, that you know heavily mocked unit tests can pass while production breaks, and that you can articulate a ratio without reciting the testing pyramid as dogma. Judgment about what is not worth testing at all is the strongest signal here.
How to structure your answer
- Split by whether the risk is logic or integration.
- Call out the mock heavy test smell.
- Describe the shape of suite you aim for.
- Say what you deliberately do not test.
Example answer
I split it by where the risk lives. If the risk is logic, branches, rounding, edge cases in a state machine, that is a unit test, and it should be fast enough that I run the whole file on save. If the risk is at a seam, my SQL actually returning what I think it returns, JSON serializing the way the client expects, middleware rejecting an expired token, that is an integration test with a real database in a container. The heuristic I use is mock count: if I need four mocks to get a test running, that test asserts my mental model of those four things, and my mental model is exactly what is wrong when it breaks in production. I also try to be honest about what I do not test. A thin controller that just passes through, or a getter, is covered incidentally and testing it separately is maintenance cost with no signal. The suite I want is lots of fast unit tests and maybe twenty integration tests over the paths where money or auth is involved.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- How do you keep integration tests from becoming slow and flaky?
- What is your view on coverage targets?
- Where do contract tests fit between services?
Related software engineer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions