Verify an application against a mock dependency
Before you begin
- Plan
- Included in Pro and Team. How plans and limits work
- Role
- Editor or higher to run a verification.
- You need
- A machine token with **Preview environments for pull requests** under **What is it for?**, as in [Create a preview environment for each pull request](/guides/cli/preview-environments/)
- An application you can start on your machine or in CI, and point at another address for the payment service it calls
A verification run starts the dependency your application calls, as a fresh MockHub project for each case, then exercises the application and checks two things: what the application answered, and which calls the dependency received. A checkout that retries a failed payment three times passes; one that retries once, or sends a new idempotency key each time, fails with the same suite.
-
Write the dependency’s configuration, such as
payment.mockhub.yaml, with the answers it should give. A response sequence such as503, 503, 201is repeatable; random values, non-fixed delays, chaos profiles and webhooks are refused, because two runs would differ. -
Write the suite,
mockhub.verification.yaml. Each case lists the requests to send to your application and what to expect, and the calls the dependency must have received:format: 1name: checkout retry recoverydependency:config: ./payment.mockhub.yamltargets:app:baseUrlFromEnv: TEST_APP_URLcases:- id: retries-with-one-orderobservationMs: 5000steps:- id: checkoutrequest: { target: app, method: POST, path: /checkout, json: { cartId: cart-1 } }expect: { status: 201 }dependencyAssertions:- id: payment-attemptsmatch: { method: POST, path: /payments }count: { equals: 3 }- id: stable-keymatch: { method: POST, path: /payments }sameAcrossCalls: { header: Idempotency-Key, required: true } -
Check it offline:
Terminal window mockhub verify validate --file mockhub.verification.yaml -
Write a small script that points your application at a case’s dependency, and run the suite with it. The script runs before each case with
MOCKHUB_DEPENDENCY_URLandMOCKHUB_DEPENDENCY_KEYset; the application sends the key in anX-MockHub-Keyheader on every call to the dependency.Terminal window TEST_APP_URL=http://localhost:8080 MOCKHUB_TOKEN=... \mockhub verify run --file mockhub.verification.yaml --before-case ./point-app-at-dependency.sh
Result
Section titled “Result”The report lists each case’s assertions, each marked as reported by the CLI or observed by MockHub, and ends with Verdict: passed. The command exits 0 only when every required assertion passes. An assertion that failed exits 1; anything MockHub could not decide, such as a missing result or a call it could not account for, is inconclusive and exits 2, so it never reads as a pass.
Using your own test framework
Section titled “Using your own test framework”mockhub verify start --file mockhub.verification.yaml prints each case’s dependency address and key once. Run your tests against them, write the outcomes as JSON or JUnit with one result named case/assertion each, and seal the run with mockhub verify finish RUN --results results.xml. Those results are labelled client-reported: MockHub never upgrades them. Renew the lease with mockhub verify heartbeat RUN every 20 seconds. For multiple cases, call mockhub verify open-case RUN CASE before exercising each one, then mockhub verify seal-case RUN CASE after its observation interval. Only one case is open at a time. A single case opens automatically when the run starts; an expired lease cannot be renewed.
See the results
Section titled “See the results”Settings → Verification lists the runs of your workspace, newest first, and opens one to show each case’s assertions with the outcome, where the evidence came from, and what was expected against what was observed. You see your own runs; an Admin or Owner sees every run. Export report saves the sealed report as a file, and Cancel run stops a run that is still going. The report is kept for the time your plan allows.
Captures and contract assertions
Section titled “Captures and contract assertions”A step’s capture reads a typed value from its response into memory for that case. Later requests reference the capture name through queryFromCapture, headersFromCapture or jsonFromCapture, without template expressions:
- id: create request: { target: app, method: POST, path: /orders } expect: { status: 201 } capture: [{ name: order-id, type: string, pointer: /id }]- id: read request: target: app method: GET path: /orders queryFromCapture: { id: order-id } expect: { status: 200 }Captured values never enter the report. A missing or wrongly typed capture makes the dependent step inconclusive. To compare an application response with a dependency operation’s response schema, use expect: {contract: {operation: "GET /orders"}}; the check reads the case’s pinned contract, and only a conclusive valid response passes.
A step or dependency assertion can declare required: false and a source of developer, contract or modelSuggested. An optional missing result does not block success; a failure still fails. A dependency assertion’s order lists method/path pairs in the order MockHub admitted the calls, including repeats; unrelated paths are ignored.
Limits
Section titled “Limits”- Cases run one request at a time. The report makes no claim about concurrent requests, a controlled clock, or the application’s own state between cases.
- Calls are listed in the order MockHub admitted them, which can differ from the order they arrived.
- A run lasts at most 15 minutes, a case admits up to 1,000 calls, and each case uses one preview environment from your plan.
- The CLI seals a case after its observation interval, before opening the next. Later calls to a sealed case are refused.
- JSON assertions are inconclusive for duplicate keys or integers beyond JavaScript’s safe range. A known status or header failure survives an unreadable body.
- The plan’s evidence allowance covers the suite, the dependency, the record of its calls and the report together. All of them expire together after the time your plan allows, and an expired report is never rebuilt from the current mocks.