Stateful Behaviour

Most web services tend to have some state, which changes as you and
others interact with it. So it’s pretty useful to be able to simulate
this when you’ve swapped a real service for a test double.

Scenarios

WireMock supports state via the notion of scenarios. A scenario is
essentially a state machine whose states can be arbitrarily assigned. It
starting state is always Scenario.STARTED. Stub mappings can be
configured to match on scenario state, such that stub A can be returned
initially, then stub B once the next scenario state has been triggered.

For example, suppose we’re writing a to-do list application consisting
of a rich client of some kind talking to a REST service. We want to test
that our UI can read the to-do list, add an item and refresh itself,
showing the updated list.

Resetting scenarios

The state of all configured scenarios can be reset back to
Scenario.START either by calling WireMock.resetAllScenarios() in
Java, or posting an empty request to http://<host>:<port>/__admin/scenarios/reset.