← All topics

Testing Junior interview questions and answers

78 questions for a Testing (Junior) interview - with correct answers, explanations and links to the docs.

Take this quiz
  1. 1.What is the main goal of automated tests?
  2. 2.What does a unit test check?
  3. 3.What does an integration test check?
  4. 4.What is an end-to-end (E2E) test?
  5. 5.What does the classic test pyramid recommend?
  6. 6.What does the “testing trophy” by Kent C. Dodds put the most weight on?
  7. 7.Which layer of the testing trophy catches typos and wrong types before tests even run?
  8. 8.What is a regression?
  9. 9.What does the Arrange–Act–Assert (AAA) pattern describe?
  10. 10.What should a test check - behaviour or implementation details?
  11. 11.What does test coverage measure?
  12. 12.Is 100% coverage a good goal on its own?
  13. 13.What are Jest and Vitest?
  14. 14.Which files does Jest pick up as tests by default?
  15. 15.What do describe and it (test) do?
  16. 16.What is the difference between toBe and toEqual?
  17. 17.How does toStrictEqual differ from toEqual?
  18. 18.Why does this check fail and how do you fix it?
  19. 19.How do you check that a function throws an error?
  20. 20.What does .not do in expect(value).not.toBeNull()?
  21. 21.Which matcher checks that an array contains an element?
  22. 22.What is beforeEach used for?
  23. 23.What do it.only and it.skip do?
  24. 24.How do you test an async function that returns a promise?
  25. 25.How do you check that a promise rejects?
  26. 26.What does watch mode (vitest / jest --watch) do?
  27. 27.Why is it useful that each test is independent?
  28. 28.What is a good name for a test?
  29. 29.Which environment do component tests usually run in under Jest/Vitest?
  30. 30.What is a mock in testing?
  31. 31.What does jest.fn() / vi.fn() create?
  32. 32.How do you check that a callback was called with specific arguments?
  33. 33.How do you make a mock return a value?
  34. 34.What does jest.spyOn(obj, "method") / vi.spyOn do?
  35. 35.What is a stub?
  36. 36.Why mock network requests in unit and integration tests?
  37. 37.What is MSW (Mock Service Worker)?
  38. 38.What does mockClear() (or vi.clearAllMocks()) do?
  39. 39.What is a risk of mocking too much?
  40. 40.How do you make a test that uses Math.random() deterministic?
  41. 41.What is the main principle of Testing Library?
  42. 42.What does render from React Testing Library do?
  43. 43.Why use screen instead of queries returned by render?
  44. 44.Which query does Testing Library recommend first?
  45. 45.How do you find the “Save” button?
  46. 46.What is the difference between getBy, queryBy and findBy?
  47. 47.How do you check that an element is NOT on the page?
  48. 48.Which query should you use for an element that appears after data loads?
  49. 49.Where do matchers like toBeInTheDocument, toBeVisible and toHaveValue come from?
  50. 50.What is better for simulating user actions: fireEvent or user-event?
  51. 51.How do you type text into an input with user-event v14?
  52. 52.How do you find an input by its label?
  53. 53.When is getByTestId appropriate?
  54. 54.What is wrong with this test?
  55. 55.How do you check the result of clicking a counter button?
  56. 56.What does screen.debug() do?
  57. 57.What does toHaveBeenCalledTimes(1) check on a prop callback after a click?
  58. 58.What does a snapshot test do?
  59. 59.Why do Testing Library queries by role also improve accessibility?
  60. 60.What are Playwright and Cypress used for?
  61. 61.Which browsers can Playwright run tests in?
  62. 62.What is the recommended way to find a button in Playwright?
  63. 63.Do you need sleep/waitForTimeout before clicking in Playwright?
  64. 64.What does await expect(page.getByText("Saved")).toBeVisible() do in Playwright?
  65. 65.What does headless mode mean?
  66. 66.How do you find an element in Cypress by a dedicated test attribute?
  67. 67.Why should E2E tests be few and focused on key user flows?
  68. 68.What is a flaky test?
  69. 69.What does playwright codegen do?
  70. 70.What is TDD (test-driven development)?
  71. 71.Where do tests usually run automatically?
  72. 72.Which of these is the best candidate for a unit test?
  73. 73.What does test.each / it.each do?
  74. 74.What should a single test ideally check?
  75. 75.Why doesn't this test catch a bug?
  76. 76.What does the expect.assertions(n) call guarantee?
  77. 77.Which test is the right place to check that a form shows “Required” when submitted empty?
  78. 78.Why test a custom hook through a component (or renderHook) rather than calling it directly?