WireMock part 2: match requests and shape slow and broken answers
Choose which calls a stub answers, set the status, the delay and a fault, and make a stub change its answer after a first call.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: a post sorting office. A clerk reads the address and the rules before choosing a bin. Some bins hold a letter back. One bin holds a damaged letter. A set of bins changes after the first letter arrives.
Mei is testing Daily List, a to-do list app. Tom uses the stubs in screen checks. Leo needs a slow answer and a broken answer so he can prove the error paths. Lily should see a loading state and a clear error, not a crash.
What it is: This is still WireMock, the tool on your machine that pretends to be an HTTP (Hypertext Transfer Protocol) service. A is a condition in the request part. The call must meet every condition. A waits a set number of milliseconds, or it fails on purpose. A millisecond is one thousandth of a second. A WireMock scenario state is a named step so the same call can return a different answer next time. A scenario starts in the state Started. WireMock is not the real partner. A match miss returns 404. That miss is the tool working, not the app breaking.
Why it matters: Real partners are flaky, costly and hard to break on purpose. Match rules, delays, faults and scenario states let Mei prove a loading state, a time-out and an empty list when she chooses. Without them, those paths stay untested until they hurt Lily.
PLAIN WORDS · 6 in this section
- stubs
- a simple fake part that gives fixed answers
- hypertext
- text that links to other pages
- milliseconds
- thousandths of a second
- millisecond
- one thousandth of a second
- flaky
- passing sometimes and failing sometimes with no product change
- untested
- not yet tried to see if it works
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 Specify match criteria and response shape.
- Read
- Hold
- Change
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| The clerk reading the address | The match rule |
| Letters held back for an hour | The delay |
| A bin of damaged letters | The fault |
| Bins that change after the first letter | The scenario state |
WHERE THIS PICTURE STOPS
- A clerk may read by hand, but a rule runs the same each time.
- Held letters arrive later, but a fault may never arrive.
- Bins change in one office, so the state belongs to one server.
HOOK
Read, hold, damage, change.
TELL A FRIEND
Rules, delays, faults and states.
OFTEN MIXED UP WITH WireMock part 1: run it and write a first stub. That topic writes one stub that answers one call. This one chooses which calls match and shapes slow, broken and changing answers.
PRACTISE AND KEEP
Sources for this topic — 4 sources
- Implementation-specific
Request matching (WireMock documentation) ↗ — WireMock · Current matching: header contains is substring; JSONPath returns non-null scalar or nonempty object/array; opened6 November2026.
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.
WireMock topic review, 8 November 2026: URL matching: path and query versus path only, plus request attributes. Current official page opened 8 November 2026.
- Implementation-specific
Stubbing (WireMock documentation) ↗ — WireMock · Current Stubbing: request/response mapping, priority lower number/default5/latest matching at equal priority, explicit save mappings endpoint; opened6 November2026.
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.
- Implementation-specific
Simulating faults (WireMock documentation) ↗ — WireMock · Current fault simulation: fixedDelayMilliseconds and EMPTY_RESPONSE versus HTTP response; opened6 November2026.
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.
WireMock topic review, 8 November 2026: Per-stub fixed delays and bad responses. Current official page opened 8 November 2026; delays are milliseconds and connection faults differ from status replies.
- Implementation-specific
Stateful behaviour (WireMock documentation) ↗ — WireMock · Current stateful behaviour: Started, state transition and POST /__admin/scenarios/reset; opened6 November2026.
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.
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.