← All topics

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