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

Give a decision rubric for when to mock an external dependency (a third-party API, a database, a cache) versus calling the real thing in a test. Name the factors your rubric weighs, and explain how the right answer can differ between a local development run, a CI pipeline, and a staging environment.

MediumTechnical
50 practiced

You are writing integration tests for a service that depends on a rate-limited third-party API. Propose a checklist of practices to keep the tests stable and safe to run in CI without exceeding the provider's rate limits or causing real side effects. Explain which parts of your checklist rely on mocking versus other techniques, and how you would categorize existing tests by how much they depend on that external dependency.

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

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.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.