Generate API assertions from a response, then make them mean something

An empty Tests tab is the biggest obstacle to having tests at all. Generate from response removes it: send the request once, click, and you have a set of checks that pass. Then the real work starts, which is turning "passes today" into "fails when something's wrong".

What it writes

For a response like:

JSON
{ "id": "inv_93k2", "status": "open", "total": 4200, "currency": "EUR", "lines": [ … ] }

you get rows similar to:

SourcePathOperatorExpected
Status codeequals200
HeaderContent-Typecontainsapplication/json
Response time (ms)less thana budget based on this response
JSON body$.idexists
JSON body$.statusexists
JSON body$.totalexists
JSON body$.currencyexists
JSON body$.linesexists

The Last response column shows each check against the response you just got, so they all show green right away.

Tighten the field checks

"$.total exists" catches a removed field and nothing else. Change each row to what the field promises:

PathBetter check
$.idmatches regex ^inv_[a-z0-9]+$
$.statusequals open for this request, or a JSON Schema enum
$.totalis type number (or equals {{expectedTotal}})
$.currencyequals EUR
$.linesis type array, and $.lines.length at least 1

Use {{variables}} in the expected value when it depends on earlier requests: $.customerId equals {{customerId}} checks that the invoice belongs to the customer you created.

Revisit the response-time budget

The generated budget comes from one response on your machine. That may be too tight for CI or too loose for an endpoint that should be fast. Set it from what users would notice, or move response time to a run-level --max-p95 gate (see performance budgets with p95).

Delete what doesn't belong

  • Checks for fields that aren't part of the contract (debug info, internal timestamps).
  • Duplicates of rules already inherited from the collection or folder. The request's Tests tab lists inherited assertions below its own, so you can see the overlap. See assertions on a collection or folder.

Add the checks it can't guess

Generation sees one response. It can't know:

  • that total must equal the sum of the lines;
  • that the list is sorted newest first;
  • that a second call returns the same id.

Those need a post-response script. Script results and assertions land in the same results list.

In test suites

In a suite's Edit panel, Generate from the last response does the same after a run, and asks where the checks go: Only in this suite, or Save to the request, which adds them to the request's Tests tab so every suite and collection run checks them. For contract checks, saving to the request is usually right.