skip to content

Lifecycle and Isolation

How a stub server is started, where it sits relative to the suite that needs it, and what is wiped between tests. Leaked stub state is a top cause of flaky suites.

on this pageshow

explore

questions

page 1 of 2

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

level: juniorimportance: must knowfreq 70%

answer

  1. the server configures itself over HTTP
  2. everything under one admin prefix
  3. collection resource for stub mappings
  4. POST one, GET the list, DELETE all
  5. WireMock: /__admin/mappings

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.

solid answer

~50 s

WireMock serves a control API for itself under the `/__admin` prefix, on the same port as the stubbed responses, so a running server stays programmable over plain HTTP. `GET /__admin/mappings` returns the stub mappings registered right now, each with the id WireMock holds it under. A `POST` to WireMock's `/__admin/mappings` registers one new mapping from the JSON body and returns it with that id — the handle you later use for `GET`, `PUT` or `DELETE /__admin/mappings/{id}`. `DELETE` on WireMock's `/__admin/mappings` is the blunt one: it clears every registered mapping in a single call, including any a neighbouring fixture put there. Because these are ordinary HTTP calls rather than a Java-only API, a Node or Python suite can stub a lighthouse maintenance API with nothing but an HTTP client, and a `curl` on the collection is a complete answer to *what is this server configured to do*.

go deeper

for a junior

Be ready to name the path — /__admin/mappings — and say what GET, POST and DELETE do on it. The point of the question is that WireMock is configurable while it is running, not only when it starts.

for a middle

Explain that POST returns the mapping with the id WireMock assigned, and that this id is what every single-mapping call afterwards addresses. Say precisely what DELETE on the collection clears and what it leaves alone.

for a senior

Show that you treat the admin API as a control plane you own: register from the case, capture ids, and remove exactly what you registered, so one fixture's stubs never quietly decide another fixture's result.

for a principal

Own the team rule for how suites drive stub servers — programmed over /__admin at run time versus a fixed set nobody edits — and be able to argue the cost of each in reviewability, reproducibility and debugging time.

## The two kinds of traffic a WireMock server answers A running WireMock server answers two quite different kinds of request on the same port. The first is the traffic your code under test sends — a `GET /lighthouses/BEACHY-HEAD/lamp` aimed at what the code believes is the lighthouse maintenance API — and WireMock answers it from whichever stub mapping matches. The second is traffic aimed at WireMock **itself**, and all of it lives under the `/__admin` prefix. That second surface is the admin API: an ordinary HTTP API whose resources are the server's own configuration rather than the fake upstream's data. WireMock's `/__admin/mappings` is the collection resource for the stub mappings that server currently holds. The three calls in the question are the collection-level operations on it, and together they are the minimum you need to drive a stub server from outside the process that started it. The consequence people miss is that a WireMock server is **programmable**, not merely configured. A stub server that only reads its mappings when it boots forces a restart for every change. A server with a live control API lets a test add a stub, run one case against it, and take it away again while the process stays up. ## WireMock's `GET /__admin/mappings` — read the registered set A GET on the collection returns the stub mappings the server holds right now, each carrying the id WireMock stores it under. Two things follow: - A test or a human can **discover** what is loaded instead of assuming it. If a lighthouse suite fails because the lamp endpoint answered something unexpected, the first diagnostic is to read the set back and see what the server thought it should answer. - The document it returns is the export half of a round trip. WireMock's `POST /__admin/mappings/import` accepts a document of that same shape, so what you read out can be fed back in. ## WireMock's `POST /__admin/mappings` — register one stub at run time A POST to the collection registers exactly **one** new mapping from the JSON body you send, and returns that mapping with the id WireMock assigned it. That id is the handle for everything single-mapping that follows: - In WireMock, `GET /__admin/mappings/{id}` reads that one mapping back. - In WireMock, `PUT /__admin/mappings/{id}` replaces that one mapping. - In WireMock, `DELETE /__admin/mappings/{id}` removes that one mapping and leaves the rest registered. A case that keeps the id can clean up precisely after itself. A case that throws the id away has only the blunt instrument left. What goes *inside* the posted body — which matchers select the request, what the canned reply contains — is a subject of its own; the admin API's job here is carriage. It takes the definition, stores it, and hands you back a way to address it. ## WireMock's `DELETE /__admin/mappings` — clear the whole set A DELETE on the collection removes every registered mapping in one call. It is the right tool when a fixture owns the server outright and wants a clean slate, and the wrong tool when a single stale stub is the problem, because it also destroys whatever a neighbouring fixture registered. Blurring the collection call with the `{id}` call is the commonest mistake on this surface. | WireMock admin call | effect | |---|---| | `GET /__admin/mappings` | list the mappings registered right now | | `POST /__admin/mappings` | register one mapping, get its id back | | `DELETE /__admin/mappings` | remove every registered mapping | | `GET /__admin/mappings/{id}` | read one mapping back | | `PUT /__admin/mappings/{id}` | replace that one mapping | | `DELETE /__admin/mappings/{id}` | remove that one mapping | | `POST /__admin/mappings/import` | load a document of many mappings | ## Why "it is plain HTTP" is the whole point The admin API is not a Java API with an HTTP transport bolted on; it is an HTTP API that WireMock's own Java DSL happens to call. Being able to state the consequences is what separates a candidate who has used the tool from one who has only read about it: 1. **Language independence.** A Node, Python, Go or Kotlin suite can register a lighthouse stub with nothing but an HTTP client, and no client library can do anything over the wire that `curl` cannot. 2. **Inspectability.** A `curl` on WireMock's `/__admin/mappings` is a complete debugging session for "what is this server configured to do right now". 3. **Change without restart.** Stubs can be added between two steps of one scenario, so the fake upstream can be reconfigured mid-test. 4. **Symmetry.** Everything you register you can read back, address by id and remove — which is what makes precise per-case cleanup possible at all. By contrast, MockServer exposes its own control plane under a different prefix entirely and registers stubs with `PUT /mockserver/expectation`, so admin knowledge does not transfer between the two by guessing. ## Where this surface stops WireMock's `/__admin` prefix carries far more than mappings. The requests the server received, scenario state, recording control, files and settings each have their own resources under the same prefix, and each is a separate subject with its own rules. For this question the boundary is simple: in WireMock, `/__admin/mappings` is where stub definitions live, it is addressable while the server runs, and GET, POST and DELETE on the collection read the set, add one to it and empty it.

  • How does a test discover the id of a mapping it registered a moment ago?
    It reads the id from the response to `POST /__admin/mappings`, which returns the stored mapping with the id WireMock assigned. If the id was thrown away, `GET /__admin/mappings` lists the registered set and every entry carries its id, so the mapping can be found again by the definition you recognise. Capturing the id at registration is the cheap option; searching the collection afterwards is the recovery.
  • Does WireMock's admin API listen on a different port from the stubbed responses?
    No — `/__admin` is served on the same port as the stubbed traffic, which is why that prefix is reserved and a stub cannot claim a path underneath it. One consequence worth saying out loud: anything that can reach the fake upstream can also reconfigure it, so the admin API is a control plane and should be treated as one.
  • Why would a suite register stubs over the admin API rather than ship one fixed set?
    Because the stub a case needs often depends on the case: one wants the lighthouse lamp endpoint healthy, the next wants it answering 503 for the same station. Registering from the test keeps the assumed upstream behaviour beside the assertion that depends on it, and `DELETE /__admin/mappings/{id}` lets the case remove exactly what it added.

saying these in an interview costs you the question

  • Says WireMock must be restarted to add a stub
  • Thinks only the Java client can register mappings
  • Confuses DELETE /__admin/mappings with deleting one stub
  • Cannot name the path stub mappings are registered on
  • Assumes the admin API needs its own separate port
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

Why start an embedded WireMockServer with wireMockConfig().dynamicPort() instead of a fixed port?

level: middleimportance: must knowfreq 70%

basics

~20 s

A fixed port makes the fixture depend on a machine-wide resource nobody owns, so any other process already holding it fails the suite. dynamicPort() has WireMock take a free port at start-up, and the test reads the resolved address back.

open as a page

What replaces WireMock's WireMockRule when an embedded fixture moves from JUnit 4 to JUnit 5?

level: middleimportance: must knowfreq 58%

basics

~20 s

WireMockRule is WireMock's JUnit 4 integration, published in wiremock-junit4. On JUnit 5 you take wiremock-junit5 and use either the declarative @WireMockTest annotation, which injects a WireMockRuntimeInfo, or WireMockExtension when you need to configure the instance yourself.

open as a page

What does a payment provider's own sandbox prove that a stub you write yourself cannot?

level: middleimportance: must knowfreq 62%

basics

~20 s

A provider's sandbox proves your request is acceptable to code you did not write: their validation, refusal rules and state transitions run for real. A stub only proves your client handles the answers you already imagined. Neither is production.

open as a page

How do you run the wiremock/wiremock image so it serves your committed scaffolding-inspection stubs?

level: middleimportance: must knowfreq 66%

basics

~20 s

Bind-mount the directory holding mappings and __files onto /home/wiremock, the root the wiremock/wiremock image uses, and publish the server's port. Launcher flags added after the image name reach WireMock itself. No image of your own is needed.

open as a page

In WireMock, what happens once --max-request-journal-entries is exceeded on a shared instance?

level: seniorimportance: must knowfreq 49%

basics

~20 s

WireMock's journal is bounded once --max-request-journal-entries is set, and passing the bound silently evicts the oldest entries. Nothing errors and nothing warns. A count taken afterwards under-reports what a long-lived shared instance received, so the answer is wrong, not missing.

open as a page

Why does a WireMock stub set that works under java -jar return 404s in the wiremock/wiremock container?

level: seniorimportance: must knowfreq 58%

basics

~20 s

WireMock's standalone launcher reads mappings and __files beneath one root directory. The wiremock/wiremock image sets that root to /home/wiremock. A bind mount landing anywhere else leaves the mapping set empty, so every scaffolding-inspection request goes unmatched and comes back 404.

open as a page

One long-lived WireMock serves every team's pipeline. When has that shape stopped paying for itself?

level: principalimportance: must knowfreq 52%

basics

~20 s

A shared WireMock has outgrown its pipeline once its singular surfaces collide. It keeps one journal whose cap other teams exhaust, one admin API any job can rewrite, and one health signal that hides both. Measure those before deciding.

open as a page

Which WireMock artifact do you declare to run an embedded stub server in a Java test?

level: juniorimportance: should knowfreq 64%

basics

~20 s

Declare the aggregate WireMock artifact, org.wiremock:wiremock, which pulls in the whole embedded library. WireMock 4 also publishes separate modules such as wiremock-core and wiremock-junit5 as an alternative for narrower dependencies. The old wiremock-jre8 artifact no longer exists.

open as a page

In a payment provider's sandbox, why must a test use the provider's designated inputs?

level: juniorimportance: should knowfreq 55%

basics

~20 s

Sandbox outcomes are triggered by inputs the provider designates, not by data that merely looks realistic. Ordinary values fall through to the success path. A refusal or a review hold stays unreachable until you send the published trigger.

open as a page

How do you start WireMock's standalone jar on a chosen port with your own stub directory?

level: juniorimportance: should knowfreq 70%

basics

~20 s

Run java -jar wiremock-standalone.jar with --port for the listening port and --root-dir for the directory holding mappings and __files. Without --root-dir the server roots itself in the current working directory. --verbose prints what the server is doing to stdout.

open as a page

In WireMock, what does POST /__admin/mappings/import do that POST /__admin/mappings does not?

level: middleimportance: should knowfreq 52%

basics

~20 s

WireMock's POST /__admin/mappings registers one stub mapping per call and hands it back with its id. WireMock's POST /__admin/mappings/import takes a document holding many mappings and loads the whole batch in a single call, adding to what is already registered.

open as a page

Why is a suite that calls a vendor-hosted mock service for a seed-bank inventory API not hermetic?

level: middleimportance: should knowfreq 47%

basics

~20 s

A hermetic suite depends only on what it brings with it. Calling a vendor-hosted mock adds the network, the vendor's availability and an account other people can edit. Any of those can turn a build red without your code changing.

open as a page

In mountebank, why is a base-port-plus-worker-index scheme worse than letting mb assign the port?

level: middleimportance: should knowfreq 46%

basics

~20 s

Nothing on the machine promises that block is yours. A second suite, a leftover process or another service can already hold one, and the worst outcome is not a bind failure but a worker quietly reaching another run's imposter.

open as a page

In mountebank, what happens to an imposter's port when a parallel worker finishes or dies?

level: middleimportance: should knowfreq 48%

basics

~20 s

Nothing releases it automatically. One mb process holds every imposter's listening socket for as long as the imposter exists, so a worker that dies without deleting its imposter leaves the port bound on that machine until mb itself exits.

open as a page

In WireMock, how does resetScenarios() differ from resetRequests() on a turbine-status stub server?

level: middleimportance: should knowfreq 54%

basics

~20 s

WireMock's resetScenarios() returns every scenario to its initial state and touches nothing else. resetRequests() empties the request journal and touches nothing else. Neither call removes a stub mapping, and the two stores are fully independent of each other.

open as a page

What does WireMock's GET /__admin/health tell a CI job waiting on a shared stub server?

level: middleimportance: should knowfreq 64%

basics

~20 s

WireMock's GET /__admin/health answers 200 only once the admin API is serving, so a pipeline polls it rather than the TCP port. It proves the process is up. It does not prove your bakery pre-order mappings are loaded.

open as a page

In WireMock, why can PUT /__admin/mappings/{id} lose parts of the stub you meant to keep?

level: seniorimportance: should knowfreq 48%

basics

~20 s

WireMock stores what you send to PUT /__admin/mappings/{id} as the whole mapping under that id. It is a replacement, not a patch, so any matcher missing from your body is gone. Read the mapping first, then put it back complete.

open as a page

In WireMock 4, why does an embedded fixture's call to stubMapping.setRequest() no longer compile?

level: seniorimportance: should knowfreq 46%

basics

~20 s

WireMock 4 made its core data classes immutable and gave them builders, so the in-place setters on StubMapping are gone. Instead derive a new mapping: WireMock 4's StubMapping.transform takes a lambda that sets the request on a builder.

open as a page

Your seed-bank inventory stubs live in a vendor's hosted mock account — how do you keep them reviewable?

level: seniorimportance: should knowfreq 52%

basics

~20 s

Definitions held in a vendor account change outside your version control. Treat that hosted mock as an environment, not a repository. Restrict who may edit it, keep an exported copy under review, and record who changed what and when.

open as a page

Your team's tram fare-inspection sandbox account is shared by parallel CI runs — what breaks?

level: seniorimportance: should knowfreq 48%

basics

~20 s

Shared sandbox state breaks isolation. Parallel runs see each other's records, share a throttle you cannot raise, and get no teardown at all. The provider owns the data and the outages, so partition per run and stub the rest.

open as a page

In mountebank, how do you stop two parallel workers creating marina-berth imposters on the same port?

level: seniorimportance: should knowfreq 52%

basics

~20 s

Stop computing the port yourself. Post the imposter to mountebank with no port field, and mountebank binds a free one and returns it in the created imposter. A pre-computed number is only free until someone else binds it.

open as a page

In WireMock, why do stubs registered with stubFor() vanish after resetAll() while start-up mappings return?

level: seniorimportance: should knowfreq 58%

basics

~20 s

WireMock's resetAll() delegates to resetToDefaultMappings(), which empties the live stub set and the request journal, then reloads only the mappings the server read at start-up. A stub added later with stubFor() was never a default, so it is gone.

open as a page

What does WireMock's --admin-api-basic-auth protect on a shared CI instance, and what does it leave open?

level: seniorimportance: should knowfreq 46%

basics

~20 s

WireMock's --admin-api-basic-auth makes the whole /__admin surface demand credentials. Nothing on the network can then silently rewrite a shared instance's stubs. It partitions nothing, though: every job holding that one credential still shares a single mapping set.

open as a page

How would you standardise WireMock reset scope across many suites stubbing one turbine-status API?

level: principalimportance: should knowfreq 45%

basics

~20 s

Make the start-up mapping set the contract and forbid suite-wide stubFor() baselines, then let suites use only the narrow calls, resetRequests() and resetScenarios(). Reserve WireMock's resetAll() for the moment a suite genuinely wants the start-up set back.

open as a page

Which call adds a stub to a running Mountebank imposter, and what does WireMock use instead?

level: middleimportance: nice to knowfreq 40%

basics

~20 s

In Mountebank, POST /imposters/:port/stubs adds one stub to an imposter that is already listening, and PUT on that path replaces its whole stub list. WireMock has no imposter object: it registers mappings with POST /__admin/mappings.

open as a page

showing 1–30 of 32