Stand-ins for other systems: stubs and mocks
A stand-in lets you test one part without the real parts around it. Learn the stub, the mock, the driver and the harness.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: a stunt double. A film uses a stunt double for a risky scene. From far away the double looks right. It does the jump so the star does not have to. But it is not the real actor, and a close-up would show that.
Daily List is a to-do list app. Tom, the tester, wants to check the reminder code. The real mail service sends real emails, is slow, and sometimes fails. Leo, the developer, gives Tom a stand-in mail service. It looks right to the reminder code, and it does the part of the real one.
With the stand-in, Tom can ask new questions. What if the mail service says "busy"? What if it never answers? The real service would be hard to control. The stand-in does what Tom tells it.
Stand-ins like this are called test doubles. Two common kinds are the stub and the mock.
The picture has a limit. A stunt double is a person who can think. A stand-in in code says only what it was told. Also, a stand-in can drift from the real thing, and then the tests pass while the real parts fail.
(SYNTHETIC / TRAINING ONLY: Daily List and every person named in this lesson are invented.)
PLAIN WORDS · 1 in this section
- stub
- a simple fake part that gives fixed answers
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.
THE REAL JOB Choosing controlled responses and explicit assertions for one part while recognising what a leaves out.
- Stub answers
- Mock expects
- Driver calls
- Harness holds all
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| A stunt double | A test double |
| The double that just does the jump | A stub that provides configured responses |
| A checklist of expected calls | A mock with programmed call expectations |
| The film crew's set | The test harness |
WHERE THIS PICTURE STOPS
- A stunt double is a person who can think, but a stand-in in code says only what it was told.
- A double is used because the real actor is costly, but a stand-in can drift from the real part.
- A double and a star look alike from far away, but a stand-in may differ in small ways.
HOOK
Stub answers; spy records; mock expects.
REMEMBER IT THIS WAY
A contrast: two neighbours told apart by one test.
Ask what you will check. The state afterwards points to a stub with configured responses; the calls made point to a spy that records them or a mock that verifies programmed expectations.
| In the trick | What it stands for |
|---|---|
| stub | A stand-in that provides configured responses |
| mock | A stand-in with programmed call expectations |
TELL A FRIEND
A stub provides the rehearsed answer; a spy records the performance; a mock checks the agreed expectations.
OFTEN MIXED UP WITH Integration testing in practice. in practice tests parts working together. This lesson shows how to test a part when its neighbours are not there.
PRACTISE AND KEEP
Sources for this topic — 12 sources
- Market practice
Mocks Aren't Stubs (Martin Fowler) ↗ — Martin Fowler · Separates checking state from checking behaviour, and uses the words dummy, fake, stub, spy and mock for kinds of test double (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
8 November 2026: bounded Difference Between Mocks and Stubs section, mailing examples, state/behavior explanation and revision history opened. Selected practitioner vocabulary: configured stub responses, recording spies and programmed mock expectations. Article revision 2 January 2007, first publication 8 July 2004. Not a universal library taxonomy.
- Market practice
Service Virtualization (WireMock glossary) ↗ — WireMock · Vendor page: a mock is a lightweight canned response, while a virtual service keeps state and models flows (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Test driver (software) (Wikipedia) ↗ — Wikipedia · A driver calls the system under test, and a stub answers calls made by the part under test (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Test harness (Wikipedia) ↗ — Wikipedia · A test harness is stubs and drivers set up to test a component (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
ISTQB Certified Tester Foundation Level Syllabus v4.0.1 ↗ — International Software Testing Qualifications Board · Section 2.2, test levels: integration testing focuses on the interactions between components or systems (confirmed against the syllabus, read in full text from a mirror copy of the publisher PDF, v4.0.1, 15 September 2024)
v4.0.1 is dated 15 September 2024 and is a list of corrections to v4.0 (21 April 2023) that reworded six learning objectives — not a cosmetic reissue. 78 pages.
Two traps this entry exists to stop. v4.0.2 is the German edition (1 March 2025, 94 pages), so sorting by version number reaches the wrong document. And the widely-repeated per-chapter question allocation "8 / 5 / 4 / 11 / 9 / 3" is wrong: it is 8 / 6 / 4 / 11 / 9 / 2, derived from three official sample-exam answer keys and confirmed against the Exam Structure Tables.
The single most consequential detail for a question bank: white-box coverage — statement and branch — is K2 "Explain", not K3 "Apply" (FL-4.3.1, FL-4.3.2, FL-4.3.3), and MC/DC, path and condition coverage are declared out of scope in §4.3. A question asking a candidate to compute branch coverage is testing something this syllabus does not.
Read through a mirror, because the publisher's own domain could not be fetched (a reachability gap, not a statement about the publisher). A 403 there is a policy refusal and says nothing about whether the document exists or is reachable elsewhere.
Anyone on an unrestricted network should open the canonical URL above and confirm the section and page numbers cited against it. Every claim drawn from this entry is written so that it can be checked against a numbered page.
Read from two independent PDF-to-markdown conversions mirrored on raw.githubusercontent.com. They are treated as faithful because they were produced by unrelated parties with different tooling, agree on the full 64-item objective set including wording, and reproduce the same internal inconsistency present in the source PDF. Chapter 1 reads "testware that supports" where Appendix B reads "that support". A conversion artefact does not replicate across two toolchains.
The licence permits attributed non-commercial extracts and use as the basis for articles. Whether a site that sells a pass may rely on that is an owner's decision, not this entry's.
7 November 2026 review: actual publisher PDF 4.0.1, 15 September 2024, 78 pages, front matter/copyright and relevant numbered operative sections 0.5–0.10 and chapters 1–6 compared with CTFLpractice lessons. Earlier mirror/search descriptions are historical access records. TheK2 white-box objectives require explanation; the source does not justify a categorical ban on small numeric illustrations that support explanation. Later Exam Rules 1.2§4.1.4 usesK2 for keyword definitions, while syllabus§0.5 usesK1; keep dated scopes distinct. No copied questions or figure assets.
- Market practice
Test development (Android Open Source Project) ↗ — Google (Android Open Source Project) · Android source docs define hermetic tests (dependencies declared and provided with the tests); Google Testing Blog 'Hermetic Servers' (2012) frames avoiding network access for speed and reliability. Search excerpts, pages not opened. Mock-server tool names left out on purpose (tools change); drift warning repeats the lesson's own L3 point in new context.
Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Hermetic Servers (Google Testing Blog, October 2012) ↗ — Google · Android source docs define hermetic tests (dependencies declared and provided with the tests); Google Testing Blog 'Hermetic Servers' (2012) frames avoiding network access for speed and reliability. Search excerpts, pages not opened. Mock-server tool names left out on purpose (tools change); drift warning repeats the lesson's own L3 point in new context.
Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Mocks Aren't Stubs (Martin Fowler) ↗ — Martin Fowler · Mocks Aren’t Stubs,2007: spies record calls and mocks verify programmed expectations; practitioner vocabulary, libraries can combine roles (relevant primary passages opened6November2026).
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
8 November 2026: bounded Difference Between Mocks and Stubs section, mailing examples, state/behavior explanation and revision history opened. Selected practitioner vocabulary: configured stub responses, recording spies and programmed mock expectations. Article revision 2 January 2007, first publication 8 July 2004. Not a universal library taxonomy.
- Market practice
Mocks Aren't Stubs (Martin Fowler) ↗ — Martin Fowler · 8 November 2026: bounded Difference Between Mocks and Stubs section, mailing examples, state/behavior explanation and revision history opened. Selected practitioner vocabulary: configured stub responses, recording spies and programmed mock expectations. Article revision 2 January 2007, first publication 8 July 2004. Not a universal library taxonomy.
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
8 November 2026: bounded Difference Between Mocks and Stubs section, mailing examples, state/behavior explanation and revision history opened. Selected practitioner vocabulary: configured stub responses, recording spies and programmed mock expectations. Article revision 2 January 2007, first publication 8 July 2004. Not a universal library taxonomy.
- Market practice
Stubbing (WireMock documentation) ↗ — WireMock · 8 November 2026: actual live WireMock Java Basic Stubbing and complete Stub Priority section/examples opened. Request mappings select configured responses; no installed-version or every-feature claim.
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail. Supplement6November2026: actual current and archived2.x stubbing pages opened; priority then most-recent matching stub; reset paths also documented in2.x. V27 supplement, 6 November 2026: relevant primary page sections actually opened; implementation-specific current product guidance, not universal standard. See full V27 audit for version and access scope.
8 November 2026: actual live WireMock Java Basic Stubbing and complete Stub Priority section/examples opened. Request mappings select configured responses; no installed-version or every-feature claim.
WireMock topic review, 8 November 2026: Basic stubbing, stub priority, unmapped replies, reset and reset-to-default: current official page opened 8 November 2026. Local examples separately checked with WireMock Java 3.13.1.
Version-specific correction: the general Reset paragraph says all mappings are removed, but WireMock Java 3.13.1 resetAll reloads defaults. See v945-wiremock-3131-reset-source and the local runtime tests. Do not infer an empty mapping list when files are present.
- Market practice
Stateful behaviour (WireMock documentation) ↗ — WireMock · 8 November 2026: actual WireMock Java Scenarios section, Java/JSON example and reset operations opened. Models selected state transitions; not reproduction of an entire real service or actual WireMock execution.
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail. V27 supplement, 6 November 2026: relevant primary page sections actually opened; implementation-specific current product guidance, not universal standard. See full V27 audit for version and access scope.
8 November 2026: actual WireMock Java Scenarios section, Java/JSON example and reset operations opened. Models selected state transitions; not reproduction of an entire real service or actual WireMock execution.
WireMock topic review, 8 November 2026: Scenarios, Started state and POST /__admin/scenarios/reset. Current official page opened 8 November 2026.
- Market practice
How Pact works — consumer tests and provider verification ↗ — Pact Foundation · 8 November 2026: actual HTTP interaction, Consumer Testing and Provider Verification sections through Putting It All Together opened, page footer 23 December 2024. Consumer checks and selected provider response verification are distinct; a written contract alone is not verification. No whole transport or deployed-behavior guarantee.
Opened relevant primary passages on6November2026 via normal web search and document view. Actual consumer client against mock provider, pact generation, independent provider states and provider verification opened. Product guidance, not a universal testing standard. Original figure source bytes matched repositorye2072af34960cb19d6c132d370c2fd580ec0e55c under the documentation MIT notice.
8 November 2026: actual HTTP interaction, Consumer Testing and Provider Verification sections through Putting It All Together opened, page footer 23 December 2024. Consumer checks and selected provider response verification are distinct; a written contract alone is not verification. No whole transport or deployed-behavior guarantee.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.