Testing interview questions
48 Testing interview questions with answers, from junior to mid level.
Foundations
Core
- How many test cases does pytest run here?
- How do you assert that code raises a
ValueErrorin pytest? - What is the Arrange-Act-Assert pattern?
- You are fixing a production bug. What is the recommended first step in code?
- What are smoke tests?
- Unit test vs integration test?
- How does pytest find tests by default?
- What happens when an
assertstatement in a pytest test is false? - In testing, what is a mock?
- What is the main benefit of an automated test suite?
- What does test coverage measure?
- Which is an edge case for a function that returns the average of a list?
- Which describes a good unit test?
- What is Selenium WebDriver?
- Why should the UI test automation suite be small compared to unit tests?
Intermediate
- What is a pytest fixture?
- An in-memory
UserRepositorythat stores users in a dict and behaves like the real one is called a… - Which is a common root cause of flaky tests?
- Your project has 100% line coverage. What can you conclude?
- How do you reliably test code that depends on the current time?
- Best practice for integration tests that need PostgreSQL?
- What is
conftest.pyfor in pytest? - Why should tests not depend on execution order?
- Which assertion verifies that a mock was called exactly once with specific arguments?
- How do you test a FastAPI endpoint without calling the real database?
- What is the purpose of a load test with a tool like Locust or k6?
- How do you decide what to test and how much?
- Which locator strategy is generally the most robust in Selenium?
- Why is
Thread.sleep(5000)a bad way to wait in UI tests, and what is better? - What is the Page Object Model (POM)?
- What does
StaleElementReferenceExceptionmean? - Which JUnit 5 annotations run before each test and mark a parameterized test?
- Selenium, Playwright and Cypress: what is a fair comparison?
- How would you design a maintainable Selenium (Java) test automation framework?
Advanced
- Which patch target makes this test intercept the HTTP call?
- What problem does consumer-driven contract testing (e.g. Pact) solve?
- What does property-based testing (e.g. Hypothesis) do?
- Mutation testing measures…
- What does
patch(..., autospec=True)add? - How would you test code that calls an external payment API?
- What is Selenium Grid used for?