Skip to main content

Compare a response with an expected output

Check that a whole response matches what you expect, instead of checking one field at a time.

info

Before you start.

  • A case with a working Request.
  • The expected response, as JSON text.
  • Use Assertions for single checks such as a status code. Use Compare when the whole body, or its structure, should match.

Steps​

  1. Open the Compare tab. In the case editor, go to Compare. Both toggles start off.

  2. Turn on response compare. Switch on Compare this case's response. In Compare, keep This case's response body.

  3. Choose the source. Under Compare against, choose Expected output.

  4. Choose how strict to be. Pick a Match mode:

    Match modeUse it when
    ExactThe response must be identical. An extra field counts as a difference.
    SubsetEverything in your expected output must match, but the response may contain more fields. Good when the API may add fields later.
    Structure onlyField names and value types must match, but the values can differ.
  5. Paste the expected output. Enter the expected JSON in Expected output, for example {"id": 1, "name": "Sample"}. You can use {{variables}} and {{data.1.column}} in it.

  6. Ignore values that change every run. Under Ignore fields, click + add path and enter the path, for example $.timestamp. Ignored fields are removed from both sides and are listed as ignored in the result.

  7. Set the options.

    • Array order matters: off by default. Turn it on if arrays must be in the same order.
    • Case sensitive: on by default.
    • Numeric tolerance: two numbers whose difference is within this value count as equal.
  8. Save, publish and run. Click Save, then publish and run.

Check the result​

Open the run and the case. The Response compare section shows a table with Outcome, Field, Expected and Actual. A difference in a value shows VALUE_MISMATCH with both values, so you can see exactly what differs. See Results, history and reports.

Common problems​

What you seeWhyWhat to do
Case is Blocked with COMPARE_NOTHING_TO_COMPAREThe side being compared is empty or was not capturedRun the case once and check the request, or fix the capture.
Case is Blocked and mentions a variable{{variable}} in the expected output has no valueDeclare it and make sure an earlier case or setup step sets it.
Fails on a field that changes every runA timestamp, id or similarAdd it under Ignore fields.

To compare against a value captured from a log, or against a fixed-length record, see Compare.