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.

MediumTechnical
83 practiced

Implement a small Node.js mock server that returns a configurable response for GET /users/:id. Test code should be able to set the response payload and status for a given id at runtime through a control endpoint, and reset it between tests. Outline the code and explain how a test would use this server.

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.

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.

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

Explain how threads, async/await, and separate processes each affect test isolation, resource usage, and the risk of nondeterministic behavior in a test runner. What would you recommend for designing a parallel test runner that avoids shared-state issues and memory leaks, including how you would scope fixtures and decide which tests are safe to parallelize versus which need to stay serial?

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.