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

MediumTechnical
56 practiced

Explain mocking versus stubbing versus service virtualization for integration tests. For each technique, describe when you would use it, its benefits and limitations in terms of fidelity versus control, how it affects long-term test maintenance, and how you would fit it into a CI workflow for a backend dependency.

MediumTechnical
50 practiced

Compare the main strategies for virtualizing an external service in tests: hand-written contract-based stubs, a standalone mock server generated from an API contract, and network-level record-and-replay of real traffic. For each, discuss maintenance overhead, fidelity to production behavior, and how it scales when many tests run in CI. How would you decide it is safe to rely on one of these instead of the real dependency?

HardTechnical
42 practiced

For large-scale performance and load testing, argue when using mocked components is acceptable and when you need real dependencies. Propose a hybrid plan that mixes mocked and real services to measure system capacity and find bottlenecks, while keeping test cost and time reasonable and avoiding conclusions that a fully mocked run could not support.

HardSystem Design
56 practiced

Your organization runs polyglot microservices across several languages, and two teams' independently hand-written mocks of the same internal service have already drifted out of sync with each other and with the real service. Propose an approach to keep mocking and stubbing consistent across languages so cross-service tests stay trustworthy as the organization grows, and explain how you would enforce it in CI.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.