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

Java's static and final methods and classes are notoriously hard to mock with a plain mocking framework. Explain why, and describe at least two approaches to work around it: a design-level fix and a tooling-level fix. Recommend best practices and the trade-offs each approach has for maintainability and test reliability.

HardTechnical
43 practiced

Design a test strategy using mocks and controlled scheduling to surface concurrency bugs and race conditions in a service backed by a shared, mutable counter. What techniques increase the probability of deterministically finding a real interleaving bug, rather than getting lucky or unlucky on a given run?

HardTechnical
41 practiced

You need to introduce automated tests into a large legacy monolith with minimal refactoring risk. Describe the practical seams and techniques you would create to make the code mockable and testable, and give a step-by-step plan to increase coverage while minimizing risk to the existing behavior.

MediumTechnical
45 practiced

Compare using a real in-memory database against mocking the data-access layer directly in your tests. Discuss the trade-offs in fidelity, speed, maintenance, handling schema migrations, and transactional semantics, and recommend which approach fits unit tests, integration tests, and CI.

MediumTechnical
61 practiced

Describe strategies for testing asynchronous, event-driven services that communicate through a message broker. Compare mocking at the producer/consumer boundary against running an embedded or lightweight broker in tests, and give sample patterns for verifying message contents, ordering guarantees, and side effects.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.