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 pageshowhide
explore
- Stand-In Definitions31 questions
- Incoming Request Criteria18 questions
- Canned Replies13 questions
- Lifecycle and Isolation32 questions
- Hosting Shapes13 questions
- Fresh State per Test13 questions
- Vendor-Operated Stand-Ins6 questions
- Transport Conditions22 questions
- Interposing on Traffic13 questions
- Faults and Delay9 questions
- Fidelity Risks25 questions
- Request Journal9 questions
- Permissive Defaults8 questions
- Staying Current8 questions
questions
110 · 4 sectionsIn WireMock, what does withRequestBody(equalToJson(...)) require of a request body?
basics
~20 sIn 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.
In WireMock, why does a stubbed body containing `{{request.path}}` come back unrendered?
basics
~20 sWireMock 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.
In WireMock, how do you make one dive-log endpoint answer PENDING first and SIGNED on the next call?
basics
~20 sPut 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.
In MockServer, how do you match only requests that are missing an `X-Sweep-Tenant` header?
basics
~20 sNegate 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.
In MockServer, does an expectation naming one query-string parameter still match a request that sends three?
basics
~20 sYes. 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.
In WireMock, what do GET, POST and DELETE on /__admin/mappings each do?
basics
~20 sWireMock'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.
What is a hosted mock service, and what does a team give up by adopting it?
basics
~20 sA 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.
In mountebank, how does a test worker learn the port its marina-berth imposter was given?
basics
~20 sThe 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.
In WireMock, which reset call empties the request journal without removing any turbine-status stub?
basics
~20 sCall 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.
In WireMock, how do you remove one run-time stub without clearing every other mapping?
basics
~20 sCall 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.
In Mountebank, what do proxyOnce, proxyAlways and proxyTransparent each do to a proxied request?
basics
~20 sMountebank'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.
How do you start WireMock standalone so it records the kayak-rental API into stub mappings?
basics
~20 sRun 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.
In WireMock, what do startRecording() and stopRecording() do to kayak-rental traffic?
basics
~20 sIn 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.
What does WireMock serve at GET /__admin/certs/wiremock-ca.crt, and who needs it?
basics
~20 sIt 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.
In WireMock, what do --https-port, --https-keystore and --keystore-password do?
basics
~20 sWireMock'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.
In MockServer, how do you verify that a POST to /catalogue/v1/holds actually arrived?
basics
~20 sMockServer 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.
In WireMock, what does the --no-request-journal flag switch off, and what then happens to verify()?
basics
~20 sWireMock'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.
In WireMock, what does makeStubsPersistent(false) change about the stubs a re-recording produces?
basics
~20 sWith 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.
In MockServer, what does each VerificationTimes factory assert about how often a request arrived?
basics
~20 sVerificationTimes 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.
In MockServer, what does upsert(openAPIExpectation(...)) build from an OpenAPI document?
basics
~20 sMockServer 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.