Skip to content

Test a mock before saving

Before you begin

Role
Viewer or higher.
You need
  • A project

Try it sends a request to the mock as it stands in the editor, saved or not, and shows what MockHub answers. Matching and templating run on MockHub’s own mock server, so the answer is the one this mock would give your caller. It works on an Inactive mock too, so you can check a mock before it answers anyone.

Under What to try, it answers one of two questions, and neither proves what the other does:

What to try Shows Proves
How a response looks The output of the response you have open, drafts included, whether or not it is the default That the response renders. Not that a request could reach it: selection and activation are bypassed
Which response a request gets Which of the saved mock’s responses a request would get, and the refusal when it would get none That the saved mock’s own rules choose as you expect. Not the project’s other mocks, and not live traffic
  1. On the project’s Mocks tab, select the mock’s name, or select New mock and fill it in.

  2. Select Try it. The Try this mock dialog opens with a request the mock should match: its method, its path and query string, and any headers and body it matches on. A cookie the mock matches is sent in one Cookie header, form fields as a form body, and an equals JSON document as a JSON body, with each placeholder replaced by a value it accepts. A has JSON path rule on a plain path such as $.customer.email gets a JSON body that holds the field.

  3. Change the request to the case you want to test, such as the path /orders/43. Add a request header adds a header.

  4. Under What to try, leave How a response looks chosen, and select Preview this response. Pressing Enter in the request does the same.

When the mock is attached to a scenario or uses the data store, the dialog has a Start from section to set before you send the request:

  • State of and the scenario’s name lists Started and the scenario’s states. It starts on the state the project’s scenario is in now; choose another to see how the mock answers from it.
  • Data store offers Empty, no records, and Current records, a copy of the project’s records in the collections the mock uses: the one it saves to, the one its condition checks, and every store.<collection> its response reads.

Try it works on its own copy of both. The project’s scenario stays in its state, and its records stay as they are.

On a saved mock, Which response a request gets sends the request in the dialog to the saved mock, which chooses one of its responses the way the gateway does, on a copy that leaves the project’s state and records alone:

  1. Under What to try, select Which response a request gets.

  2. Leave Ask for a response by name on None: the default answers to see what an ordinary request gets, or choose one of the mock’s responses to send its X-MockHub-Response header.

  3. Select Send the request. Pressing Enter in the request does the same.

Under Response the request gets, the dialog says which response answered and how it was chosen, such as “Answered by Invalid email (invalid-email), which the request named in X-MockHub-Response.” When the mock cannot serve the response asked for, it says “Refused, and not answered with the default”, with the reason in MockHub’s usual words, as a real request would get; see Response selection unavailable.

Your unsaved edits are not part of this, and the dialog says so. A new mock has to be saved first. For a saved sequence, choose Initial sequence step before you send. The result says where the copy of the sequence started and which step the next request would get, following its repeat or stick rule, such as “The copy of the sequence started at step 1; the next request would get step 2.” The live position stays unchanged. A sequence refuses a request that names a response. To check the real thing, with competing mocks, logging and quotas, copy a request from Use this response in a request and send it to the project’s address; see Choose the response that answers.

For How a response looks, under Preview, named after the response when the mock has several, the dialog shows the status code, the response headers and the body, with its templates rendered.

When the request does not match the mock, the status is 404 and the body names the mock and says where the request differs, with what the mock expected and what the request had:

Request was not matched
Closest mock: Get order
Differences:
- URL does not match (expected: "/orders/42", actual: "/orders/43")

When the request is far from this mock, the answer says only that it was not matched.

A rule on a multipart part reads in one of two ways. A request that is not multipart is reported as [Multipart request body] is not present, and a part whose own header or body misses is reported as a header or body difference.

After a send with Start from, the dialog says where the scenario was left, such as “Moved to Settled” or “Stayed in Pending”. For a mock that saves or deletes records, it lists each one, such as “Saved u2 in users” with the value, or “Deleted u1 from users”, and otherwise says “Wrote no records.”

When the mock is linked to an operation of the project’s OpenAPI contract, the dialog also offers Preview and validate, which sends the same request and checks the response against that operation. See Check a mock against its contract.

When the mock matches its path, a header, a query parameter or the body with a regular expression, the dialog fills in a value the expression matches, such as /orders/1 for /orders/[0-9]+. It cannot work one out from an expression with a lookahead such as (?!0), a backreference such as \1, or a boundary such as \b. It does not guess a body for a has JSON path rule whose path holds [*], .*, .. or a filter, or for multipart parts. Then the dialog says “This mock matches … in a way no request could be guessed from, such as a regular expression, a JSON path or multipart parts.” For a Regex path, Request path holds the expression itself: replace it with a real path. A multipart body is typed into Request body with its Content-Type header, boundary included. A request whose Content-Type is multipart/* without a boundary is refused, as the gateway refuses it with a 400, with “A multipart request needs a boundary parameter in its Content-Type, such as multipart/form-data; boundary=x.”

The Render a sample button in an opened row of the Mocks tab uses the same request. When no request can be worked out, the row says “No sample” instead, because a request the mock does not match would show only a near miss.

If the template could not be rendered, the dialog says “The mock server could not render this body.” and shows the mock server’s [ERROR] report, with the problem in plain words and its line. A caller of the project gets a Mock response did not render error instead. When the body rendered with an error in place of a value, such as an unknown math operator, the dialog says “One value could not be generated.” and lists each one.

When the dialog can place a problem in Response body, Show in the editor closes the dialog, selects the first marked expression and opens the list of problems. The marks stay until you change that expression or send again. When it cannot place one, it says “Nothing in the body matches this; it may come from a response header.” What the reports mean is in Write dynamic responses with templates.

Try it tests one mock on its own. It cannot tell whether another mock in the project would match the same request; for that, use Test a request on the Mocks tab (Test a request against the project).

Current records copies at most 1 MB. Above that, the dialog says “Try it copies at most 1 MB of records”, with the size of the collections the mock uses; start from Empty, or clear some records on the Data store tab. The copy, and the copy of the scenario, are removed after the send, and never reach the project.

For a mock with several responses or a response sequence, Preview this response plays the response you have open, not the mock’s selection and not the sequence.

Try it never paces a stream: it lists the chunks with the time each would leave, which Play shows in turn. For an AI model response, Ask for a stream sets "stream": true in the request’s body.

An active chaos profile is ignored. The response panel says when chaos has been left out.

An [ERROR] report counts its line from the body’s first {{, with column zero at that expression. The dialog calls it a template position, and Show in the editor translates it to the expression’s position in your body.

A request does not count towards the workspace’s requests. It shares the per-second and in-flight limits with calls to the project’s address, and the plan’s size limits for request and response bodies apply too. Nothing is recorded in the request logs, and no webhook is sent. A redirect the mock answers with is shown as it is and never followed. Paths starting with /__admin cannot be tried.

To call a REST resource for real, its collection’s page on the Data store tab lists a curl command per endpoint under Try it.

Report a problem with this page