Testing Senior interview questions and answers
75 questions for a Testing (Senior) interview - with correct answers, explanations and links to the docs.
Take this quiz- 1.How do you decide where to place a test in the pyramid/trophy?
- 2.Why does Google's “Just Say No to More End-to-End Tests” argue against relying on E2E?
- 3.What is the “testing honeycomb” and where is it used?
- 4.What are Google's “test sizes” (small, medium, large) based on?
- 5.Why are the terms “unit” and “integration” test often ambiguous in discussions?
- 6.What is the difference between solitary and sociable unit tests?
- 7.What is the classical vs mockist (London school) TDD difference?
- 8.What does “don't mock what you don't own” suggest?
- 9.Which signal suggests a test suite is too coupled to implementation?
- 10.How do you justify the cost of a new E2E test to the team?
- 11.Where do contract tests fit between a frontend and its API?
- 12.What does mutation testing (e.g. Stryker) measure?
- 13.What is property-based testing (e.g. fast-check)?
- 14.Why can coverage targets backfire as a KPI?
- 15.What is the main value of TDD at a senior level beyond “having tests”?
- 16.Which are the main sources of non-determinism in tests, according to Fowler?
- 17.A test passes alone but fails when the whole file runs. What is the likely cause?
- 18.Why are automatic retries in CI dangerous if used without monitoring?
- 19.How does Playwright sharding work in CI?
- 20.What is the difference between Playwright workers and shards?
- 21.How should test data be organized for E2E tests that run in parallel against a shared environment?
- 22.What order of checks makes a CI pipeline give feedback fastest?
- 23.Why should a CI test run use
--ci(Jest) or equivalent settings? - 24.Why does
vi.mockneed to be hoisted, and what follows from it? - 25.How do you get a fresh copy of a module with module-level state in each test?
- 26.What are the main limitations of jsdom for component tests?
- 27.How does happy-dom differ from jsdom?
- 28.What is the trade-off between Vitest pools
threadsandforks? - 29.What does Vitest's
projectsoption (formerly workspace) solve? - 30.What does
expectTypeOfin Vitest test? - 31.What is in-source testing in Vitest?
- 32.What is the
testcontext in Vitest and why is it useful for concurrent tests? - 33.Why can
jest.useFakeTimers()hang a test that awaits a promise usingsetTimeout? - 34.What does
act()guarantee in React tests? - 35.How do you test async React Server Components?
- 36.How do you unit-test a Next.js Server Action?
- 37.How do you test a component inside an error boundary without noisy logs?
- 38.How do you test a component that renders through a portal (modal)?
- 39.When is it better to test a custom hook via
renderHookrather than through a component? - 40.How do you test Suspense with data loading in a component test?
- 41.Why is mocking
useStateor other React hooks a bad idea? - 42.What are the limits of jest-axe/axe-core checks in jsdom?
- 43.How do Playwright fixtures differ from
beforeEachhooks? - 44.How do you implement authentication once for the whole suite in Playwright?
- 45.What makes visual regression tests (
toHaveScreenshot) flaky, and how do you reduce it? - 46.What does
page.clockallow in Playwright? - 47.What does
toMatchAriaSnapshotcheck? - 48.What are the trade-offs of the Page Object Model in Playwright tests?
- 49.What does
expect.softdo? - 50.What does
await expect(async () => { ... }).toPass()do? - 51.How can E2E tests run against recorded API traffic?
- 52.What does
test.stepadd to a Playwright test? - 53.Why should E2E tests prefer seeding state via API instead of the UI?
- 54.Why can't Cypress commands be mixed with
async/await? - 55.Why does this custom check not retry, and how do you fix it?
- 56.What does
cy.origin()solve? - 57.When might Cypress be a better choice than Playwright?
- 58.What is the difference between a mock and a fake?
- 59.When is verifying interactions (that a mock was called) the right assertion?
- 60.Why is dependency injection helpful for testability?
- 61.How do MSW handlers help beyond unit tests?
- 62.What is a risk of MSW handlers drifting from the real API?
- 63.How do you mock a class constructor with Vitest/Jest?
- 64.What do Storybook interaction tests add?
- 65.What is visual testing of components (e.g. with Storybook + Chromatic) good at?
- 66.How do you test a feature behind a feature flag?
- 67.How do you approach testing in a large legacy frontend without tests?
- 68.How do you test date/time formatting for different locales and time zones reliably?
- 69.What does test-level parallelism require from test code?
- 70.Which approach to test-ids is most maintainable when roles and names aren't enough?
- 71.Why might a senior engineer argue against a test suite full of
toMatchSnapshot()for components? - 72.What is the main risk of testing through
data-testidonly? - 73.Which metric best shows the health of a test suite to a team?
- 74.How can E2E tests catch hydration mismatches and other runtime errors that don't break the visible UI?
- 75.What does
vitest --changed(or Jest--changedSince) give a large repository, and what is its limit?