Skip to content

Test a request against the project

Before you begin

Role
Viewer or higher.
You need
  • A project

Try it answers for the mock you are editing. Test a request answers for the whole project: which of its saved mocks accept a request, which one the answer comes from, and where each of the others differs. Nothing is sent to the project’s address, logged or forwarded, and no scenario or record moves.

  1. On the project’s Mocks tab, select Test a request. It is there in an empty project too, and opens its own page.

  2. Choose the method and enter the path and query string under Method and path, such as /orders?status=open. The path starts with /.

  3. Add any headers with Add a request header, and a body under Request body. Two headers of one name are sent as one value, joined with a comma, as the project’s address receives a repeated header.

  4. Under Try it against, leave The closest mocks chosen.

  5. Select Test request.

To start from a request the project received, open it under Request logs with Request and response and select Test against current mocks; see Test a logged request against today’s mocks.

The result starts with Now: and one of these:

Heading Means
2 active mocks accepted this request Several active mocks take the request. The project’s address serves one of them, and which one is not defined; the answer shown is the first
1 active mock accepted among those tried One of the mocks tried takes it. A mock that was not among them could take it too
No active candidate accepted among those tried None of the active mocks tried takes it
“Get order” accepted this request or did not You tried one mock alone
The gateway refuses this request with 422 or 400 The request names a response in X-MockHub-Response that the project’s address would refuse; the reason shows below it

Below it, each mock tried is listed with Active or Inactive, the status it answered with, and what happened: Accepted it, Did not accept it with the first difference, such as “Method: HTTP method does not match”, or that it accepted the request but its response did not render or it refused the response the request named in X-MockHub-Response. Answers marks the mock the answer comes from. Details lists every difference, with what the mock expects and what the request sent, and which response answered. Edit mock opens the mock in the editor, on the response that answered; for a Viewer it reads Inspect mock. When you come back with your browser’s back button, the request you wrote is still there, ready to test against the changed mock; the earlier result is not, as the mocks may have changed. Start over clears the request.

A mock attached to a scenario or a data-store condition is tried as if they hold, and says so, such as “Tried as if scenario “checkout” is in “paid”.” Under Response, the answer’s status and body show, up to its first 8 KiB.

When the project records all traffic, a note says the gateway forwards every request to your upstream and asks no mock. When it forwards only what no mock answers, the note appears when no active mock accepted the request.

A request that names a response in X-MockHub-Response is refused rather than forwarded or answered 404 when no active mock accepts it, when the mock that accepts it cannot serve that response, or while the project records all traffic; a header that is empty, repeated or not in the form the mock’s editor copies is refused with 400. See Choose the response that answers.

If you change the request after testing it, even while the test runs, the result stays but is headed For the request as sent, with the method and path it answers. Select Test request again to try the request as it is now.

The closest mocks are found by method and path, at most three. When the mock you expected is not among them, select Try one mock alone under the result, or choose Try this mock alone under Try it against. Choose the mock under Mock, by name or path, and select Test request. The request stays as you wrote it. A mock tried alone answers even while it is Inactive, so you can check one before you activate it.

  • At most three mocks are tried, each on its own, not together. With several accepting, it cannot say which one the project’s address would choose.
  • A scenario’s state and a data-store condition are assumed to hold, and no scenario moves; an active chaos profile is left out, and the result says so.
  • A request does not count towards the workspace’s requests. Each mock tried shares the per-second and in-flight limits with calls to the project’s address: when a limit refuses one, the whole test fails with how long to wait, and Test request runs it again. The request body size of the plan applies.
  • HEAD and paths starting with /__admin cannot be tried, and a Host header cannot be sent.
  • What you enter stays only while you work in the project, in this browser tab, and is cleared when you switch projects or reload the page. It is not saved, and it is never put in the page’s address.

Report a problem with this page