One rule for every request: assertions on a collection or folder
Some checks belong to the API, not to one endpoint. "Never a server error." "Always JSON." "Under a second." Writing them on each request means writing them forty times and forgetting the forty-first. Writing them once, where they apply to everything, is better.
Rules that fit the whole collection
Open the collection, then its Tests tab:
| Check | Source | Path | Operator | Expected |
|---|---|---|---|---|
| No server errors | Status code | less than | 500 | |
| Responses are JSON | Header | Content-Type | contains | json |
| Fast enough | Response time (ms) | less than | 1000 | |
| No version leak | Header | X-Powered-By | does not exist |
These are the checks you'd want on every request anyway, and they're the ones nobody writes when adding a new endpoint at 6 pm.
"Status less than 500" is deliberately loose. It doesn't say the request succeeded: negative tests expect 400s and 404s. It says the server didn't fall over, which is true for every request in the collection.
Rules that fit a folder
Folders are where the more specific rules go:
- Admin:
X-Request-Idexists, if the admin gateway sets it and the public one doesn't. - Public:
Cache-Controlcontainspublic(see testing caching headers). - Deprecated:
Sunsetexists (see deprecation headers). - Lists:
$.datais typearray, and$.data.lengthis at most100(your page size).
A request in Lists inherits the collection's rules and the folder's.
The order they run in
For a request in Orders API / Admin / Refunds:
- the request's post-response script;
- the collection's assertions;
- Admin's assertions;
- Refunds' assertions;
- the request's own assertions.
All results land in the same list on the response panel's Tests tab, failures first, with expected and actual values. A failed inherited assertion fails the request, exactly like its own would, in the runner, in the CLI and in JUnit and HTML reports.
Seeing them on a request
Open any request's Tests tab. Below its own assertions, the inherited ones are listed read-only, each with its source ("from collection", "from folder Admin") and its result against the last response you got. You see straight away which rule a request breaks, without opening the folder.
To change an inherited rule, edit it where it's defined, then save that collection or folder.
Exceptions
Sometimes one request can't follow a rule. A file download isn't JSON; a 204 has no Content-Type. Two ways to handle it:
- Move the rule down to the folders it really applies to, and leave the exception in a folder without it.
- Move the exception into its own folder, for example Downloads, outside the folder that has the JSON rule.
Folders that mirror "what kind of response this is" usually make inherited rules simpler than folders that mirror the URL structure.
Scripts on folders, too
Assertions cover most rules. For the ones that need code, a collection or folder can also have pre-request and post-response scripts, which run before the request's own script for the same phase:
// Folder post-response script: every list is sorted newest first
const items = pm.response.json().data || [];
pm.test('newest first', () => {
for (let i = 1; i < items.length; i++) {
pm.expect(items[i - 1].createdAt >= items[i].createdAt).to.equal(true);
}
});In suites
Test suites run requests with their collection's rules, plus any checks the suite adds. Save to the request in the suite's Edit panel adds a check to the request's own Tests tab instead; for rules that apply everywhere, put them on the collection.