{"post":{"slug":"what-is-a-test-double-2026","title":"What Is a Test Double in 2026? The Five Types","excerpt":"A test double is any stand-in object used in place of a real dependency during a test. Dummy, stub, spy, fake, and mock are the five specific kinds, and the differences matter more than the shared name suggests.","category":"code","date":"July 21, 2026","author":"ByteLedger Team","content":"<span class=\"dropcap\">A</span> test double is any object that stands in for a real dependency during a test, the general term for the whole category. Mock gets used as a catch-all for this entire category in everyday conversation, which is convenient in casual speech and genuinely confusing in a design discussion, because the five specific kinds of test double behave differently and prove different things. The taxonomy comes from Gerard Meszaros and was popularized by Martin Fowler: dummy, stub, spy, fake, and mock.\n\n## What changed in 2026\n\n- **The vocabulary spread beyond testing specialists.** More style guides and team documentation now define these five terms explicitly, since \"just use a mock\" stopped being precise enough once teams started debugging why mock-heavy suites were brittle.\n- **Fakes gained ground relative to mocks** for testing anything with real logic worth exercising, like an in-memory repository standing in for a database, as teams pushed back against long chains of mock expectations.\n- **Static typing made doubles safer to maintain**, with generated doubles from interfaces catching a mismatch between a double and the real thing at compile time in many statically typed languages.\n\n## The five kinds of test double\n\n| Kind | What it does | Example |\n| --- | --- | --- |\n| Dummy | Does nothing; exists only to satisfy a required parameter | An empty object passed to a constructor that requires a logger but never uses it in this test |\n| Stub | Returns fixed, canned data when called | A user repository stub that always returns the same test user |\n| Spy | Records how it was called, checked after the fact | A stub that also remembers how many times it was called, then the test inspects that record |\n| Fake | A real, working, simplified implementation | An in-memory list standing in for a database table |\n| Mock | Pre-programmed with expectations, verified during the test | An object that fails the test itself if it is not called with the exact expected arguments |\n\nThe rows are ordered roughly by how much real behavior the double has, from none in a dummy to a full simplified implementation in a fake, with mock sitting apart from the other four because it actively asserts, rather than passively standing in.\n\n## Why the distinction matters in practice\n\nA stub and a mock can be built from the exact same mocking library and look nearly identical in code. The difference is what the test checks. If the test inspects the return value your code produced using the double, the double acted as a stub. If the test inspects whether the double was called correctly, the double acted as a mock. For a deeper look at that specific practice, see [what mocking in tests actually means](/blog/what-is-mocking-in-tests-2026).\n\n## When each kind earns its place\n\n- **Dummy** — only when a function signature requires an argument the test genuinely does not care about.\n- **Stub** — when your code needs data from a dependency but the test is not about that dependency, like feeding a fixed exchange rate into a currency conversion test.\n- **Spy** — when you need to confirm a side effect happened, like an analytics event being sent, without failing the whole test the moment the call looks slightly different.\n- **Fake** — when the real behavior of the dependency matters enough that canned data would miss real bugs, and a full real instance is too slow or heavy for a unit test.\n- **Mock** — when the entire point of the test is confirming an interaction took place, like verifying a refund API was called exactly once with the correct order ID.\n\n## The most common mistake\n\nReaching for a mock by default, for everything, regardless of what the test is actually trying to prove. A mock is the most rigid of the five: it fails the test the moment the interaction does not match its expectations exactly, including on harmless refactors that do not change behavior. A stub or a fake is often the less brittle, more honest choice when you are not actually testing an interaction.\n\n## FAQ\n\n**Is a mock the same as a test double?**\nNo. A test double is the general category; a mock is one of five specific kinds within it, alongside dummy, stub, spy, and fake.\n\n**What is the difference between a stub and a mock?**\nA stub returns data and is not itself checked; the test verifies the output your code produced using that data. A mock is checked directly; the test verifies the mock was called the way it should have been.\n\n**Is a fake the same as the real implementation?**\nNo, but it behaves like one. A fake has real, working logic, an in-memory database instead of a real one, for example, just simplified enough to be fast and safe inside a test.\n\n**Do I need a mocking library to create any of these?**\nNo. All five can be hand-written as plain objects or classes. Mocking libraries exist to remove the repetitive boilerplate, especially for mocks and spies, not because the concepts require special tooling.\n\n## Where to go next\n\n- [What is mocking in tests in 2026?](/blog/what-is-mocking-in-tests-2026)\n- [Unit testing best practices in 2026](/blog/unit-testing-best-practices-2026)\n- [What is test-driven development in 2026?](/blog/what-is-test-driven-development-2026)","hue":320,"metaTitle":"What Is a Test Double in 2026?","metaDescription":"What is a test double in 2026? The five kinds, dummy, stub, spy, fake, and mock, defined clearly with examples of when each one actually belongs.","keywords":["test double 2026","what is a test double","dummy stub spy fake mock","martin fowler test doubles","types of test doubles","fake object testing","test spy explained","test double vs mock","test double examples","testing terminology"],"tldr":["**Test double is the umbrella term; mock is just one of five kinds** — dummy, stub, spy, fake, and mock each do a different job, and mock gets used loosely for all of them in casual conversation.","**The difference is what each one does when called** — a dummy does nothing, a stub returns fixed data, a spy records calls, a fake has real working logic, a mock verifies expected interactions.","**A fake is the most underused of the five** — an in-memory version of a real dependency is often more reliable and less brittle than a mock with a long list of expectations.","**Picking the right one is a design decision, not a syntax choice** — the same mocking library can produce a stub, a spy, or a mock depending on how you use it.","**Skip:** calling every test double a mock in a design discussion — precise vocabulary here is not pedantry, it changes what the test actually proves."],"readTime":"4 min read","wordCount":890},"related":[{"slug":"mocking-explained-2026","title":"Mocking explained in 2026: when to mock, when to fake, when to stop","excerpt":"Mocking is both the most useful and most abused technique in testing. This 2026 guide explains mocks vs fakes vs stubs, and when each belongs in your test suite.","category":"code","date":"April 20, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":306},{"slug":"what-is-mocking-in-tests-2026","title":"What Is Mocking in Tests? 2026 Guide","excerpt":"Mocking replaces a real dependency with a fake object that records how it was called, so a test can verify behavior without touching a real database or network. Here is how mocking works in 2026.","category":"code","date":"July 23, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":280},{"slug":"what-is-an-api-mock-server-2026","title":"What is an API mock server in 2026? A fake backend on demand","excerpt":"An API mock server is a real, running server that simulates an API without the real backend behind it, useful for parallel development, demos, and tests that should never touch production. Here is how it fits in 2026.","category":"code","date":"July 21, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":310}],"sameCategory":[{"slug":"bazel-build-explained-2026","title":"Bazel Explained: What Hermetic Builds Actually Cost","excerpt":"Bazel delivers reproducible, precisely cached builds and demands that you describe everything. Here is what you get, what it costs, and who should say no.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":145},{"slug":"graphql-federation-2026","title":"GraphQL Federation: One Graph, Many Teams","excerpt":"Federation composes independently-owned subgraphs into a single API. Here is what it solves, the operational cost it adds, and when a simpler gateway is enough.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":300},{"slug":"hermetic-builds-explained-2026","title":"Hermetic Builds Explained: Same Inputs, Same Output","excerpt":"A hermetic build depends only on declared inputs. Here is what that property gives you, the common leaks that break it, and how to move toward it incrementally.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":130},{"slug":"monorepo-tooling-compared-2026","title":"Monorepo Tooling Compared: What You Actually Need","excerpt":"Monorepo tools solve task orchestration and caching, not repository layout. Here is what each tier provides and how to tell when you have outgrown the simple option.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":150}],"newer":{"slug":"what-is-a-tender-offer-2026","title":"What Is a Tender Offer? A 2026 Shareholder Guide","excerpt":"A plain-language guide to tender offers in 2026 — how they differ from buying on the open market, why companies and acquirers use them, and what a shareholder should check before responding.","category":"finance","date":"July 21, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":215},"older":{"slug":"what-is-a-thunderbolt-5-2026","title":"What is Thunderbolt 5 in 2026: speed, ports, and who needs it","excerpt":"Thunderbolt 5 roughly doubles the bandwidth of Thunderbolt 4 and adds smarter dynamic allocation. Here is what it actually changes for real laptops and docks in 2026.","category":"tech","date":"July 21, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":240}}