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

Give examples of using mocks or stubs to simulate exception and error conditions, such as a network timeout, a database constraint violation, or a message-broker disconnect. Explain why deliberately exercising these error paths in tests is valuable for product reliability, beyond just covering the happy path.

MediumTechnical
60 practiced

Mocking can both reduce and introduce test flakiness. Describe at least three ways this happens in practice, and for each give a mitigation an SDET could apply to keep the suite stable and predictable 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
49 practiced

How do you test code that depends on the current time, such as token expiry or a scheduled task? Describe the tools and approaches you would use to make the test deterministic and safe from timezone or daylight-saving issues.

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.