On this page4 sections
ReferenceIntermediate4-6 min reference

WireMock

WireMock is an HTTP mock server: it stands in for a real API so you can test against controlled responses — including errors and delays you can't reliably trigger on the real thing. This is a quick lookup of the stub anatomy and matchers; for full setup and code, see the Snippets library linked below.

Stub anatomy

A stub maps a request match to a response:

PartHolds
request.methodGET / POST / …
request.urlPath / urlPatternexact path or regex
request.headers / queryParametersheader/query matchers
request.bodyPatternsmatch on body (JSON path, regex)
response.statusthe status code to return
response.jsonBody / bodythe payload
response.fixedDelayMillisecondssimulate latency

Request matchers

MatcherMatches
equalToExact value
matching / doesNotMatchRegex
containingSubstring
equalToJson (+ ignoreExtraElements)JSON body
matchingJsonPathA JSON path expression
absentHeader/param must NOT be present

What it's great for

  • Forcing error responses (500, 429, timeouts) the real API won't give on demand.
  • Latency injection to test spinners, retries, and timeouts.
  • Scenarios (stateful stubs) to model a sequence: e.g. pendingcomplete.
  • Verification: assert the system-under-test called the endpoint N times with the expected body.

Common mistakes

  • Over-broad matchers (urlPattern: .*) so the wrong stub answers.
  • Mocking so much that tests pass while the real integration is broken — pair with contract or E2E tests.
  • Forgetting to reset stubs/scenarios between tests → order-dependent flakiness.
  • Asserting only the response, never verifying the request that was sent.

// Related resources