VHow do you decide what to cover with unit tests versus integration tests?
Interviewer questionTesting
Interviewers for developer and QA roles want to see a quality mindset: you think about what can go wrong, how likely it is and how to find it early. Tools matter less than reasoning. A candidate who explains why a test exists is stronger than one who names five frameworks.
Give each answer in three steps: a short definition, an example from a real project, and the trade-off. In testing, almost every rule has an exception, and saying so shows that you have worked with a real test suite and not only read about one.
- ✓Words → phrases → sentences → speaking
- ✓Answer meaning
- ✓Language
Common questions and sample answers
What is the test pyramid, and why does it matter?
What the interviewer wants to hear. The idea of many fast tests at the bottom and few slow ones at the top, with the reason: cost, speed and clarity of failures.
Sample answer to practise aloudThe test pyramid is a model for balancing tests. At the bottom there are many fast unit tests, in the middle fewer integration tests, and at the top a small number of end-to-end tests through the real interface. The reason is cost. Unit tests run in milliseconds and point to the exact problem. End-to-end tests are slow, fragile and harder to debug, but they check that the whole system works. If a team has mostly end-to-end tests, the feedback is slow and the suite becomes unreliable. I use the pyramid as a guide, not as a law. For a service that is mostly integration with a database, I may write more integration tests.
What is the difference between a unit test and an integration test, and when do you use a mock?
What the interviewer wants to hear. Clear definitions, a rule for what to replace with a mock, and the risk of over-mocking.
Sample answer to practise aloudA unit test checks one small piece of logic, like a function or a class, in isolation. It is fast and does not need a network or a database. An integration test checks that several parts work together, for example my code and a real database. I use a mock or a stub to replace a dependency that is slow, random or outside my control, like a payment gateway or the clock. But I do not mock everything. If a test only checks that my mock was called, it proves little and breaks whenever I refactor. For the database layer, I prefer a real database in a container, because it finds real problems, such as a wrong query.
What is a flaky test, and how do you deal with it?
What the interviewer wants to hear. Typical causes, a method to find the real cause, and a policy that protects the team from ignored failures.
Sample answer to practise aloudA flaky test sometimes passes and sometimes fails on the same code. It is dangerous, because people stop trusting the suite and start ignoring red builds. The common causes are fixed waiting times, shared state between tests, random or time-based data, and unstable external services. First I reproduce the problem, by running the test many times or in a different order, and I read the logs. Then I fix the cause: wait for a condition instead of sleeping, isolate the data, control the clock. If I cannot fix it quickly, I quarantine the test and create a ticket, so it does not block everyone. I never just add a retry and forget it.
How do you manage test data?
What the interviewer wants to hear. Isolated tests, readable data creation, and attention to privacy when real data is involved.
Sample answer to practise aloudGood test data is realistic, isolated and easy to understand. For unit tests, I create the data inside the test with small builders or factory functions, so the reader sees what matters. For integration and end-to-end tests, each test should create the data that it needs and clean up after itself, or run in a transaction that is rolled back, so tests do not depend on each other. I avoid sharing one big database dump, because nobody knows what is inside, and one change breaks many tests. I never copy real customer data into a test environment without anonymising it, because of privacy rules.
What is test-driven development, and do you use it?
What the interviewer wants to hear. The red, green, refactor cycle, real benefits, and an honest view of where it fits and where it does not.
Sample answer to practise aloudTDD means test-driven development. I write a failing test first, then the smallest amount of code that makes it pass, and then I refactor while the tests stay green. This is the red, green, refactor cycle. The benefit is that I think about the behaviour and the interface before the implementation, and I get a safety net for later changes. I find it most useful for business logic and for bug fixes: I first write a test that reproduces the bug. I use it less for exploratory work, like a new user interface, where I do not yet know what I am building. For me, it is a tool, not a rule.
How to say the key terms
- mock
- mok (rhymes with "clock")
- flaky
- FLAY-kee
- regression
- rih-GRESH-un
- fixture
- FIKS-cher
- assertion
- uh-SUR-shun
- coverage
- KUV-er-ij
- deterministic
- dih-TUR-mih-NIS-tik
Useful phrases for answering
- I would test the behaviour, not the implementation.
- First I write a failing test that reproduces the bug.
- I would mock only what I do not control.
- What is the risk if this fails in production?
- The test should fail for one reason only.
- I would make the test deterministic first.
- That belongs in a unit test, not an end-to-end test.
Common mistakes to avoid
- Quoting "90 percent coverage" as proof of quality. Coverage shows which lines ran, not whether the tests check anything useful. Say what your tests protect.
- Saying "I made a test" or "I did a bug". The usual collocations are "write a test", "run the tests", "find a bug" and "fix a bug". Learn them as ready-made chunks.
- Describing testing as "clicking through the application". Talk about risk, automation and where each kind of test fits.
- Blaming others, for example "developers write bad code" or "QA is too slow". A strong answer shows shared ownership of quality.
- Claiming that you test everything. Nobody can, so explain how you choose: by risk, by impact and by how often the code changes.
Frequently asked questions
Do I need to know a specific test framework?
Name the one you used, for example JUnit, pytest or Jest, and explain how you structured tests with it. Concepts such as isolation, mocks and test data are the same in every framework, and interviewers care about them more.
How do I show a QA mindset in an interview?
Talk about risk and users: what could go wrong, what the impact would be, and how you would find it early. Mention edge cases, exploratory testing and clear bug reports with steps to reproduce. A short story about a bug you found before release works well.
What if I am asked to write test cases on the spot?
Think aloud and use a simple order: the normal case, boundary values, empty or invalid input, and failure cases. Saying the categories aloud shows structure, even if you do not have time to write every case.
Reading an answer is not the same as saying it. Practise each question out loud, then compare the meaning and the language of your own answer.
Try SpeakRole ↗Other topics in this area