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

Medium

Hard

Other topics

HTML/CSS · Browser · JavaScript · TypeScript · React · System Design · Accessibility · Web Performance · Networking/Security · DSA

← Search all 265 questions