Skip to content

simulating faults

Bernard Niset edited this page Sep 12, 2022 · 1 revision

One of the main reasons it's beneficial to use web service fakes when testing is to inject faulty behaviour that might be difficult to get the real service to produce on demand. In addition to being able to send back any HTTP response code indicating an error, WireMock is able to generate a few other types of problem.

Per-stub fixed delays

A stub response can have a fixed delay attached to it, such that the response will not be returned until after the specified number of milliseconds:

{
  "request": {
    "method": "GET",
    "url": "/delayed"
  },
  "response": {
    "status": 200,
    "fixedDelayMilliseconds": 2000
  }
}

Global fixed stub delays

A fixed delay can be added to all stubs by doing a PATCH with JSON document of the following form to http://<host>:<port>/__admin/settings:

{
  "fixedDelayMilliseconds": 500
}