Skip to main content
Automation
DEFINITION

What is Test Double?

A test double is any object that stands in for a real dependency during testing, replacing a database, service, or collaborator with a controllable substitute so a test can run in isolation, deterministically, and fast. The main kinds are dummies, stubs, spies, mocks and fakes, and the term covers all of them the way stunt double covers every stunt.

No account needed · Scored in under a minute against a senior rubric

IN DEPTH

What does Test Double mean in practice?

Test double is the umbrella term (coined by Gerard Meszaros) for the family of stand-ins testers use to isolate the code under test from its real dependencies. Rather than calling a real database or payment service, you inject a double you control, making tests faster, deterministic, and focused on one unit of behavior.

There are five commonly cited types. A dummy is passed around but never actually used (it just fills a parameter). A stub returns canned answers to calls, used to drive the code down a particular path. A fake has a working but simplified implementation (for example, an in-memory database) suitable for tests but not production. A spy records how it was called so you can assert on the interactions afterward. A mock is pre-programmed with expectations and verifies that the right calls happened, often failing the test itself if they did not.

The practical distinction interviewers probe is stub vs mock: stubs provide state (return values you assert on), while mocks verify behavior (interactions you expect). Overusing mocks couples tests to implementation details and makes them brittle, so good engineers reach for the lightest double that does the job.

WHY IT MATTERS

Why do interviewers ask about Test Double?

Mocks vs stubs (and the broader test-double vocabulary) is a staple of unit-testing interviews. Using the terms precisely, and knowing when to verify behavior with a mock versus provide state with a stub, signals real testing maturity, not just buzzword familiarity.

EXAMPLE

What does Test Double look like in a real project?

Testing an order service that calls a payment gateway, you replace the gateway with a stub that returns "approved" to test the success path and "declined" to test the failure path, no real charges, no network. To assert the service actually called the gateway exactly once with the right amount, you use a mock or spy and verify the interaction.

TIP

How should you talk about Test Double in an interview?

Define test double as the umbrella term for stand-in dependencies, then list the five types (dummy, stub, fake, spy, mock). Nail the key distinction: stubs provide canned state you assert on; mocks verify expected interactions. Add that over-mocking makes tests brittle.

FAQ

Common questions about Test Double

What are the five types of test doubles?

Dummy (passed but unused), stub (returns canned answers to drive a path), fake (a simplified working implementation like an in-memory DB), spy (records calls so you can assert on them), and mock (pre-programmed with expectations that it verifies). They differ in whether they provide state or verify behavior.

What is the difference between a mock and a stub?

A stub provides canned return values so the code under test can proceed, you assert on the resulting state. A mock is set up with expectations about how it should be called and verifies those interactions, often failing the test itself if the expected calls did not happen. Stubs check state; mocks check behavior.

Related Resources

Dive deeper with these related interview prep pages.

FREE TOOLS  /  no signup

Free QA career tools, no account needed

Instant and private, everything runs in your browser. Try them before you sign up.

EXEC.NOW

Ready to Ace Your QA Interview?

Practice explaining test double and other key concepts with our AI interviewer.

Join 500+ QA engineers already practicing with AssertHired.

Question 1 · Automation · Mid-levellive scoring

A test passes locally but fails in CI about one run in five. Walk me through what you check first, and why.

Scored on the same four dimensions as the real thing: Technical accuracy · Coverage · Clarity · Best practices.

Rather skip ahead? Create a free account

FREE.TO.START  ·  7.DAY.TRIAL ON PAID PLANS
Written by , Senior QA Automation Engineer, 50+ QA candidate interviews conductedLast updated July 2026