Skip to content

Save and apply named fixtures

Before you begin

Plan
Included in Free, Pro and Team. How plans and limits work
Role
Viewer or higher to inspect fixtures and Editor or higher to save and apply fixtures.
You need
  • A project

Save a named fixture once, then apply it before each run to restore the same records and named scenario states.

The project dashboard has no tab for fixtures, so use the CLI or an AI assistant.

  1. Prepare the project’s records and scenario states with the data and responses you want to start from.

  2. Stop traffic to the project.

  3. Run mockhub fixture capture checkout-ready --description "One user before payment" --env staging.

  4. Before your next run, run mockhub fixture apply checkout-ready --env staging --yes.

After capture, the CLI prints Captured fixture checkout-ready v1., and mockhub fixture list shows the fixture with its id, version and description. mockhub fixture export writes its collections, records and named scenario states to a file.

After application, the CLI prints Applied fixture checkout-ready v1. The project’s records match the fixture, extra records and collections are removed, and all scenarios and response sequences restart, those of inactive mocks included, before the listed named states are assigned.

You can apply the same fixture again after your test changes data or advances a stateful flow. An empty fixture removes all records and resets scenarios and sequences to their start.

Write the definition below to a file and run mockhub fixture save --file checkout-ready.json. mockhub fixture export checkout-ready --output checkout-ready.json writes a saved one back out for editing.

A changed definition advances its version. If another member changes it first, export it again and inspect the latest definition before applying it.

{
"name": "checkout-ready",
"description": "One user before payment",
"collections": [
{
"name": "users",
"records": [{ "key": "u1", "value": { "id": "u1", "name": "Ada" } }]
}
],
"scenarioStates": [{ "name": "Payment", "state": "Pending" }]
}

Every listed scenario must be defined in the project. Its state must be Started or one of that scenario’s states. To apply a state beyond Started, activate a mock that references the scenario. Names and record keys within a collection must be unique. A collection name starts with a lowercase letter, followed by up to 47 letters, digits or underscores.

Neither the CLI nor an AI assistant deletes a fixture. Deleting one through MockHub’s API removes the saved definition and leaves runtime state as it is.

A private reusable pack includes all saved fixture definitions when you save it.

  • Capture reads records and scenario states one after the other, so requests during a capture can leave them out of step. Stop requests before capture and application.
  • Applying a fixture replaces records and scenario states in several steps. A failure before it starts clearing records changes nothing. A failure after that says the records and states may be partly reset; fix the cause, then apply again.
  • Fixtures preserve their explicit values and named states. They do not freeze random or time-dependent template output, restore request logs or pending webhook deliveries, or remember a response sequence’s position. Application resets sequences to their first response.
  • Saved definitions count towards configuration storage. Their records must fit the project’s data-store allowance, including after a plan change.
  • Fixture definitions refer to named scenarios; changing or deleting those scenarios can make an old fixture invalid. Update the fixture before applying it.

Report a problem with this page