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.

HardTechnical
48 practiced

As a technical lead, craft a stakeholder-facing proposal to reduce brittle, over-specified mocks in the test suite for a mission-critical service. Include a cost/benefit case, a phased technical plan, a rollback plan if the change causes problems, and the metrics you would use to measure success over the next quarter.

HardTechnical
59 practiced

Your CI pipeline is unstable because several tests depend on flaky or slow third-party services. Propose a hybrid strategy that decides, dependency by dependency, whether to mock it, virtualize it, or keep a small number of real integration tests. Give criteria for which tests should stay live, and explain how you would know if that mix is drifting the wrong way over time.

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
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.

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.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.