85 Testing interview questions with answers
85 Testing interview questions with detailed answers, sorted from basic to advanced. Free to practice, with progress saved automatically.
All Testing interview questions
What is Jest? What are its main features?
How are describe, it/test, and expect used in Jest?
Mocking in Jest: how are jest.fn(), jest.mock(), and jest.spyOn() used?
What is Vitest? Why is it a good choice for Vite projects?
What is Cypress? How does it differ from Selenium?
What is Playwright? How does it compare to Cypress?
What is TDD (Test-Driven Development)? What is the Red-Green-Refactor cycle?
What is BDD (Behavior-Driven Development)? What is the Given-When-Then syntax?
How do unit, integration, and e2e tests differ, and how should you balance them?
What is snapshot testing in Jest? When should it be used?
What is code coverage? What are the different coverage metrics?
How does integration testing differ from unit testing?
How do you handle authentication in Playwright E2E tests?
What is contract testing? Why is it important in microservices?
What are test doubles — mock, stub, spy, fake — and how do they differ?
What do you typically use to test React components?
What is the AAA pattern (Arrange-Act-Assert) in testing?
How do you mock APIs in frontend tests? How does MSW (Mock Service Worker) differ from mocking fetch directly?
What are flaky tests? What causes them and how do you fix them?
Coverage thresholds in Jest: how to configure them and what are the best practices?
Testing Library: how do getBy, queryBy, and findBy differ?
Test isolation: why is it important and how do you ensure it?
Playwright: how do you write maintainable E2E tests?
What cases should you test after coding a solution?
How do you dry-run code to catch bugs before running it?
What kinds of bugs are most common in coding interviews?
How do you design good test cases when none are given?
What is the difference between Verification and Validation?
What is the difference between Error, Defect (Fault/Bug), and Failure?
What is the difference between Black-box, White-box, and Gray-box testing?
What is the difference between Functional and Non-functional testing?
What is the difference between Severity and Priority in a bug report?
What states does a Defect Life Cycle go through?
What are Equivalence Partitioning and Boundary Value Analysis, and how do they design test cases?
What is the difference between Smoke testing and Sanity testing?
What is the difference between Static and Dynamic testing?
How do the four test levels (unit, integration, system, acceptance) differ?
What is the difference between Regression testing and Re-testing?
What are the phases of the STLC (Software Testing Life Cycle)?
What is the difference between a Test case and a Test scenario?
How do you test asynchronous code in Jest? Compare returning a promise, the done callback, and resolves/rejects.
A production project has no tests at all. Where do you start?
With limited time, should you test business logic or UI first? What is a waste to test?
When fixing a production bug, do you write the test before or after the fix? Why?
If a test hits a real database, is it a unit test or an integration test? Where is the line?
What is the harm in over-mocking? Why can all tests be green while production still breaks?
How do you test code that depends on time (`Date.now`, token expiry, `setTimeout`)?
How do you keep tests deterministic when code uses UUIDs, `Math.random`, or network calls?
How do you prepare data for database-backed tests — fixtures or factories — and how do you clean up between tests?
The suite takes 20 minutes on every push and the team is starting to skip it. How do you speed it up?
CI fails randomly and passes on re-run. Should you enable auto-retry? How do you handle it properly?
Do you actually practise TDD at work? When does it fit and when does it not?
You must refactor a legacy module with no tests. How do you build a safety net first?
Which React Testing Library query should you reach for first? How do `getByRole` and `getByTestId` differ, and when is `data-testid` acceptable?
A test fails with `Unable to find an element with the text: ...` even though the text is clearly on screen in the app. What are the usual causes?
How do `fireEvent` and `userEvent` differ, and why is `user-event` recommended?
How do you test a sign-up form with validation (invalid email, short password)? What should you assert on?
A component fetches on mount and renders a list. How do you test the loading → data → empty flow?
How do you set MSW up for a test suite, and how do you simulate a 500 or a network failure for a single test?
How is `waitFor` commonly misused? When should you use `findBy` versus `waitForElementToBeRemoved`?
How do you test a custom hook (e.g. `useDebouncedValue`, `useCart`) when it renders no UI?
A component depends on Context, Router, and React Query. How do you test it without hand-wrapping providers in every test?
How does hoisting work in `vi.mock`/`jest.mock`, and why does referencing an outer variable in the factory throw `Cannot access ... before initialization`?
How do you test a search box with a 300ms debounce, and why does combining fake timers with `user-event` often hang?
`getByRole("button", { name: "Save" })` cannot find a button that is clearly visible on screen. How do you debug it?
A project has 200 snapshot files and every PR just runs `-u` and commits the result. What is wrong, and what should replace it?
Your team uses Cypress — should you migrate to Playwright? What criteria would you evaluate?
E2E tests fail randomly around filling a form and waiting for an API. Why is `waitForTimeout`/`sleep` the wrong tool, and how should selectors be chosen?
The e2e suite takes 25 minutes on CI and goes red occasionally for no clear reason. How do you configure parallelism, retries, and failure evidence?
When testing a REST endpoint, should you call the handler directly, send HTTP in-process, or spin up a real server?
What does a bug report need so a developer can reproduce it immediately without asking follow-ups?
At what point in a sprint should QA get involved? What belongs in a ticket's Definition of Done?
It works on staging but breaks in production. Which differences between the two environments usually cause that?
Your integration tests need a database. Do you use in-memory SQLite, a shared staging DB, or Testcontainers?
Running tests in parallel makes them clash over data. Do you isolate with transaction rollback, truncation, or a schema per worker?
Should you copy production data into your test environment? If not, how do you seed test data?
Your code calls a third-party API (payment gateway, SMS). How do you test it — mocks, the vendor sandbox, or recorded responses?
How do you test a consumer that reads messages from a queue (Kafka/RabbitMQ/SQS), and what exactly do you test?
You are asked to "load test this API" with k6. Which metrics do you measure and what counts as a pass?
A release is imminent and there is no time to run the full suite. What do you re-run?
Two services talk over HTTP. Without standing up the whole system for integration tests, how does contract testing (Pact) solve this?
Do database migrations need tests? How do you test a migration that changes a column already in use?
A scheduled (cron) job computes end-of-day revenue. How do you test it properly, including timezone handling?
As a developer, which security checks do you write for your own API before handing it to the security team?
Twelve bugs remain open the day before release. What determines whether you delay the release or ship with known issues?