Testing
Check responses with no-code assertions, copy values between requests with extractors, write scripts, and run whole collections.
Watch this in the tutorial: Everyday API work (2:43)A request in Getman can check its own response. Each request has a Tests tab with assertions, which need no code, and extractors, which copy a value from one response into a variable for the next request. For anything more complex, a script can add tests with gm.test. Every check appears in the response Tests tab and in the collection runner.
No-code assertions
Choose Add assertion in the Tests tab. Each row picks a kind from a menu and then the values it checks:
| Group | Kind | Example |
|---|---|---|
| Response | Status | Status is 200 |
| Response | Response time | Under 1000 ms |
| Response | Body contains | Body contains "ok" (case-sensitive) |
| Response | JSON schema | Body matches an inline JSON Schema |
| JSON body | JSON path exists | data.id is present |
| JSON body | JSON path value | data.status equals active |
| JSON body | JSON array length | data.items has at least 1 item |
| Headers | Header | Content-Type contains application/json |
The status check uses four operators: is, is not, is in range (for example 2xx) and is one of (for example 200, 201). JSON paths use dots and indexes, such as data.tokens[0].access. Values are compared by type: the number 7 matches "7" or "7.0", and strings compare exactly.
Expected values may contain variables such as {{expected_status}}. The test name shows the template, not the resolved value, so secrets do not appear in names.
Read a failure
A failed check shows the expected and the actual value. A missing JSON path fails with nothing at <path>, and a non-JSON body fails every JSON check. Secret values are redacted from the message.
Status errors
A 4xx or 5xx response fails the request unless a status assertion expects that status. The result shows Status is not an HTTP error with the hint to add a status assertion. Add Status is 401 to a request that checks the unauthorized case, and the request passes.
Extractors
An extractor copies a value from a response into a variable. Choose Add extractor in the Tests tab, then set:
- Extract from: JSON path, Header, Cookie or Status code
- Store in variable: the name to write
- Scope: Runtime, Environment, Collection or Global
Runtime values last for the run and disappear when the app closes. The other scopes persist. A runtime value shadows an environment value with the same name. If the source is not in the response, the variable keeps its old value and the console shows a warning.
Extractors run before assertions, so a token is saved even when a check on the same response fails.
Scripts
Scripts run in a sandbox with a 5 second default timeout and a 32 MB memory limit. A pre-request script runs before the request is sent, and a post-response script runs after the response arrives. Tests in a script use gm.test and the gm.expect chain:
gm.test("status is 200", () => {
gm.expect(gm.response.code).to.equal(200);
});
gm.test("order has a total", () => {
gm.expect(gm.response.json()).to.have.property("total");
});
Each gm.test(name, fn) records a pass or a failure. A thrown error or a rejected promise fails the test. An assertion that is never called does nothing, so always call the full form.
Common expect forms are equal, eql, include, property, lengthOf, match, above and below, plus the chain words to, be, have and not. Any other assertion throws an error that names it.
Requests cannot call each other from a script. gm.sendRequest throws. Chain requests through variables instead: a post-response script on the login request sets an environment variable, and the next request uses it in its URL or headers. Auth can do this for you through a token flow. See Auth.
Run a collection
- Choose Run collection from the collection’s menu in the sidebar, or pick the target in the runner.
- Choose Run. Use Cancel run to stop a run in progress.
- Read the results. Each request shows whether it passed and which checks failed.
For an environment that asks for confirmation, Getman stops before a POST, PUT, PATCH or DELETE and asks you to confirm it. The setting is per environment kind, under Project settings → Safety.
The command line runs the same collections:
getman run "Shop API" --workspace getman --env Local
A passing run exits with 0. A failed test exits with 1, and a request error with 2. See Installation for the command line setup.
Next steps
- Contracts turns collections into an OpenAPI document.
- Troubleshooting explains common failures in tests.