Mocking, Stubbing, and Test Isolation Questions

Isolating the unit under test from its dependencies. Covers mocks, stubs, fakes, and spies, when to use test doubles versus real dependencies, and controlling external services and time. Includes designing for isolation so tests are fast, deterministic, and focused.

MediumTechnical
54 practiced

Using pytest, write a parameterized test for a /calculate API endpoint that covers multiple input cases. The endpoint calls an external rate-limit or billing service; mock that call so the tests do not depend on the network. Show the test code demonstrating both the parametrization and the mock.

EasyTechnical
46 practiced

Explain the differences between mocks, stubs, fakes, spies, and dummies. For each kind of test double, give a concrete example from a typical web application (an HTTP API call, a database, a message queue, or a cache) and a short guideline for when you would prefer that double over the others.

EasyTechnical
57 practiced

Describe test isolation in the context of automated testing for a microservice. Explain why isolation matters, list common sources of test interference, and outline the practices you would enforce in CI to keep tests isolated.

MediumTechnical
56 practiced

Discuss lifecycle management for test doubles in a large test suite: how they get created and configured, how you verify they were used correctly, and how they get reset and torn down between tests. Propose naming and fixture-scope conventions to avoid leaking mock state between tests and keep mocks consistent across a team.

MediumTechnical
45 practiced

Explain approaches to intercept and modify network requests and responses during a Selenium test in order to simulate backend conditions. Compare using an HTTP proxy, browser-level network interception, and a service-virtualization tool, and provide a short example showing how you would stub a single JSON API response.

Unlock Full Question Bank

Get access to all 17 Mocking, Stubbing, and Test Isolation interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.