Generate tests for a saved request
generate_testsWrites pm.test assertions for status, Content-Type, and JSON body schema from a real or described response into a saved request and saves that response as a mock example. Existing tests are kept.
Instructions
Write pm.test assertions into a saved request from a real or described response: its status, its Content-Type and a JSON schema of its body (types and required fields, never values), and save the response as an example the mock server serves. from: run (default) sends the request, so it creates what a POST creates. from: example takes the status and body, or schema, the code returns, for an API that is not running anywhere yet. Tests the request already has are kept; a test with the same name is not added twice.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| body | No | With from: example, a representative response body. | |
| from | No | run sends the request and tests its response; example tests the response you describe. Defaults to run. | |
| schema | No | A JSON Schema for the body to use instead of one inferred from the response, for example built from the response type in the code. | |
| status | No | With from: example, the status the code returns (default 200). | |
| replace | No | Replace the request's test script instead of adding to it. | |
| request | Yes | Request id or path (Collection/Folder/Name). | |
| variables | No | With from: run, variable overrides for this call. | |
| contentType | No | With from: example, the Content-Type. Defaults to application/json for a JSON body. | |
| environment | No | With from: run, the environment to send it with. Defaults to the one the server was started with. | |
| exampleName | No | Example name. Defaults to the status, for example "200 OK". | |
| saveExample | No | Save the response as an example (default true). An example of the same name is replaced. | |
| allowErrorStatus | No | With from: run, write tests even when the response is 4xx or 5xx, to test an error case on purpose. |