InterviewStack.io LogoInterviewStack.io

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.

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
47 practiced

In Python, you have a function fetch_user(user_id) that calls requests.get(...) against a live API and returns parsed JSON. Write a unit test using unittest and unittest.mock that stubs the call so the test runs entirely offline, and assert both the returned data and that the call was made with the expected URL.

MediumTechnical
59 practiced

Explain the roles of unit, integration, and end-to-end tests in a delivery pipeline. For each layer, describe what should typically be mocked versus run against a real dependency, and walk through a concrete example for a payment flow showing where mocks belong and why.

MediumTechnical
53 practiced

Design tests to validate the retry and circuit-breaker behavior of a service that calls an external HTTP API. Describe how you would use a mock or a local controllable stub server to produce timeouts, slow responses, and server errors, and how you would assert on circuit-breaker state transitions and retry counts. Note any edge cases your tests should cover.

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.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.