skip to content

API Mocking & Stub Servers

Standalone servers that stand in for a dependency you cannot call: defining stubs, matching requests, and recording a real service to replay. Interviewers probe how the stub stays honest.

on this pageshow

explore

questions

110 · 4 sections

In WireMock, what does withRequestBody(equalToJson(...)) require of a request body?

level: juniorimportance: must knowfreq 72%
basics
~20 s

In WireMock, withRequestBody(equalToJson(...)) parses the request body as JSON and requires it to equal your expected document exactly. Extra fields, missing fields and reordered arrays all make it miss. Two optional flags relax extra elements and array order.

open as a page

In WireMock, why does a stubbed body containing `{{request.path}}` come back unrendered?

level: juniorimportance: must knowfreq 66%
basics
~20 s

WireMock renders a stub body only when the response-template transformer is attached to that response. Without it, WireMock treats the body as literal bytes and returns the Handlebars source unchanged. Attach it with withTransformers, or launch WireMock with --global-response-templating.

open as a page

In WireMock, how do you make one dive-log endpoint answer PENDING first and SIGNED on the next call?

level: middleimportance: must knowfreq 70%
basics
~20 s

Put both WireMock stubs into one scenario with inScenario. The first requires the start state and calls willSetStateTo to move the conversation on. The second requires that new state and answers only once the first has served.

open as a page

In MockServer, how do you match only requests that are missing an `X-Sweep-Tenant` header?

level: middleimportance: must knowfreq 57%
basics
~20 s

Negate the header name. MockServer holds request names and values as NottableString values, so a header built from not("X-Sweep-Tenant") matches only calls that carry no such header. Negating the value instead matches a header that is present but different.

open as a page

In MockServer, does an expectation naming one query-string parameter still match a request that sends three?

level: middleimportance: must knowfreq 68%
basics
~20 s

Yes. MockServer matches on a subset, not on equality. Every header, cookie and query-string parameter you name is a constraint the request must satisfy; every one you do not name is ignored, however many the client sends.

open as a page

In WireMock, what do GET, POST and DELETE on /__admin/mappings each do?

level: juniorimportance: must knowfreq 70%
basics
~20 s

WireMock's admin API at /__admin/mappings lists every registered stub on GET and registers one new stub from the posted body on POST. DELETE on the same path removes all of them. Any HTTP client can drive it while the server runs.

open as a page

What is a hosted mock service, and what does a team give up by adopting it?

level: juniorimportance: must knowfreq 62%
basics
~20 s

A hosted mock service is a stub server a vendor runs for you. Its canned replies live in an account on their platform, reachable at an address they control. What you give up is custody: review, rollback and availability.

open as a page

In mountebank, how does a test worker learn the port its marina-berth imposter was given?

level: juniorimportance: must knowfreq 66%
basics
~20 s

The POST /imposters response is the created imposter, and its port field holds the number mountebank bound. Read it from that response, or list running imposters with GET /imposters, then build the worker's base URL from it.

open as a page

In WireMock, which reset call empties the request journal without removing any turbine-status stub?

level: juniorimportance: must knowfreq 68%
basics
~20 s

Call resetRequests() on WireMock's WireMockServer, or resetAllRequests() from its static client DSL; over the admin API it is DELETE /__admin/requests. It resets the request journal alone, so stub mappings, scenario state and global settings all survive untouched.

open as a page

In WireMock, how do you remove one run-time stub without clearing every other mapping?

level: middleimportance: must knowfreq 62%
basics
~20 s

Call DELETE /__admin/mappings/{id} with the id WireMock returned when the stub was registered. That removes exactly that mapping and leaves the rest in place, while DELETE on the collection path clears every registered mapping at once.

open as a page

In Mountebank, what do proxyOnce, proxyAlways and proxyTransparent each do to a proxied request?

level: juniorimportance: must knowfreq 64%
basics
~20 s

Mountebank's proxyOnce forwards the first matching glossary request to the real service and answers later identical ones from the saved reply. proxyAlways forwards every matching request upstream. proxyTransparent forwards everything and saves nothing, staying a pure pass-through.

open as a page

How do you start WireMock standalone so it records the kayak-rental API into stub mappings?

level: juniorimportance: must knowfreq 68%
basics
~20 s

Run WireMock standalone with --record-mappings and --proxy-all pointed at the kayak-rental base URL. Every request is forwarded upstream and the real reply is written back as a stub mapping. Large response bodies are extracted into separate body files.

open as a page

In WireMock, what do startRecording() and stopRecording() do to kayak-rental traffic?

level: juniorimportance: must knowfreq 61%
basics
~20 s

In WireMock, startRecording puts the running server into recording mode against a target base URL. WireMock's stopRecording ends the session and returns a SnapshotRecordResult holding the stub mappings built from the traffic. Both are also WireMock admin routes.

open as a page

What does WireMock serve at GET /__admin/certs/wiremock-ca.crt, and who needs it?

level: juniorimportance: must knowfreq 55%
basics
~20 s

It serves the public CA certificate WireMock signs browser-proxy certificates with. A client proxied through WireMock must install it in its trust store, or the call fails before any stub is matched. The private key stays on the server.

open as a page

In WireMock, what do --https-port, --https-keystore and --keystore-password do?

level: juniorimportance: must knowfreq 64%
basics
~20 s

WireMock's --https-port opens an extra TLS listener on that port. --https-keystore points at a Java keystore holding the certificate WireMock presents there, and --keystore-password unlocks it. Omit both and WireMock serves its own bundled self-signed certificate instead.

open as a page

In MockServer, how do you verify that a POST to /catalogue/v1/holds actually arrived?

level: juniorimportance: must knowfreq 68%
basics
~20 s

MockServer keeps a journal of every request it receives, and MockServerClient.verify asserts against it. Pass a request definition describing the POST plus a VerificationTimes count. When nothing matches, verify throws an AssertionError listing the requests the journal did record.

open as a page

In WireMock, what does the --no-request-journal flag switch off, and what then happens to verify()?

level: juniorimportance: must knowfreq 46%
basics
~20 s

WireMock's --no-request-journal flag stops the server recording the requests it receives. Because nothing is recorded, verification is not weakened but abolished: the disabled journal raises RequestJournalDisabledException. A verify() call after that flag can never pass, whatever the client sent.

open as a page

In WireMock, what does makeStubsPersistent(false) change about the stubs a re-recording produces?

level: juniorimportance: must knowfreq 58%
basics
~20 s

With makeStubsPersistent set to false, WireMock keeps the regenerated stubs in memory only: they serve requests while the instance lives and vanish on restart. Its default, true, writes each one as a JSON file under the mappings directory.

open as a page

In MockServer, what does each VerificationTimes factory assert about how often a request arrived?

level: middleimportance: must knowfreq 62%
basics
~20 s

VerificationTimes carries six factories: never, once, exactly, atLeast, atMost and between. Each turns a MockServer verification from at least one matching request into a precise count assertion, so a duplicated or missing hold request fails the test rather than passing.

open as a page

In MockServer, what does upsert(openAPIExpectation(...)) build from an OpenAPI document?

level: middleimportance: must knowfreq 66%
basics
~20 s

MockServer reads the OpenAPI document, then creates one expectation for each operation it selects, matching that operation's method, path and declared parameters. Each expectation replies with the response the document declares. The entry point is upsert(OpenAPIExpectation...) on MockServerClient.

open as a page