Testing Interview Questions
20 Testing interview questions with worked answers, complexity notes, and runnable code you can edit in the browser — ordered easy to hard so you build up steadily. Free, no signup. Open any question for the full answer.
Tests as the confidence to change code
The point of a test suite is not coverage numbers — it is the freedom to change code without fear that something quietly broke. That reframing decides most of the judgment calls. Interviewers probe whether you test behavior the way a user experiences it, or whether you couple tests to internal implementation. The former survive refactors and fail only when something real breaks; the latter rot into noise, get updated on reflex, and eventually prove nothing while still costing you time on every change.
The test pyramid gives you the layering: many fast unit tests, fewer integration tests, and a small number of end-to-end tests that are slow and flaky but exercise the whole thing. The craft is choosing the right layer for each concern — testing pure logic as a unit, a rendered component through the queries a user would use, and only the critical journeys end-to-end. Test doubles (mocks, stubs, spies, fakes) are how you isolate the unit under test, and knowing which to use and when to stop mocking is a senior signal on its own.
The hard, opinion-shaped questions come next. Flakiness is usually a race condition or a dependence on timing or order, and the fix is deterministic waits, not retries. Snapshots are useful for detecting change and useless as assertions of correctness when nobody reads the diff. Deciding when end-to-end is worth its cost, how to make a slow suite fast, and where to spend limited testing effort for the highest return are the questions that reveal experience. The throughline across all of them: the more your tests resemble how the software is actually used, the more confidence they give and the less they cost you.
Easy
- The testing pyramid Test Strategy
Explain the testing pyramid. What goes in each layer, and why is the shape a pyramid rather than a rectangle? - What makes a good unit test Unit Test Quality
What properties distinguish a good unit test from a bad one? What is the AAA structure? - Testing behavior, not implementation Behavior vs. Implementation
What does it mean to test behavior rather than implementation details? Why does it matter? - Assertions and matchers: toBe vs. toEqual Assertions
What's the difference between toBe and toEqual? When do you reach for each, and what other matchers matter? - Setup, teardown, and test isolation Isolation
What do beforeEach/afterEach do, and why is shared state between tests dangerous? - Test doubles: stub, mock, spy, fake Test Doubles
Define stub, spy, mock, and fake. When would you use each, and what's the risk of over-using them? - Testing pure functions vs. side effects Side Effects
Why are pure functions the easiest thing to test, and how do you make code with side effects testable? - Code coverage: what it does and doesn't tell you Coverage
What does code coverage measure, and why is '100% coverage' not the same as 'well tested'?
Medium
- Testing React components the user's way Component Testing
How should you query and assert on a React component with Testing Library? Why 'by role' over test IDs or class names? - user-event vs. fireEvent Simulating Interaction
What's the difference between user-event and fireEvent, and why is user-event usually the right choice? - Mocking modules and the network (MSW vs. jest.mock) Mocking Boundaries
How do you mock a module vs. the network in tests, and why is intercepting HTTP (MSW) usually better than mocking fetch? - Testing async code and fake timers Async Testing
How do you test promises, code that updates after awaiting, and time-dependent logic (debounce, setTimeout)? - Testing custom React hooks Hooks
How do you test a custom hook in isolation, and when should you test it through a component instead?
Hard
- Flaky tests: causes and elimination Flakiness
What causes flaky tests, and how do you systematically hunt down and eliminate flakiness? - End-to-end testing: when and how End-to-End
When are Playwright/Cypress-style e2e tests worth it, what are the tradeoffs, and how do you keep them stable? - Testing accessibility in the suite Accessibility Testing
How do you build accessibility checks into automated tests, and what can and can't they catch? - Snapshot testing: value, pitfalls, and rot Snapshot Testing
What is snapshot testing good and bad at? How do snapshots 'rot', and how do you use them responsibly? - Visual regression testing Visual Regression
What is visual regression testing, what does it catch that DOM tests miss, and what makes it hard? - Test suite performance and parallelization Suite Performance
A test suite takes 20 minutes and blocks every PR. How do you make it fast without losing confidence? - What NOT to test, and testing ROI Test Strategy
How do you decide what NOT to test? Explain testing ROI and the 'testing trophy' vs. the pyramid.
Other topics
HTML/CSS · Browser · JavaScript · TypeScript · React · System Design · Accessibility · Web Performance · Networking/Security · DSA