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