Run different checks per environment
The same collection runs against Local, Staging and Production. Mostly the checks are the same. A few aren't:
- Staging has seeded test users; production doesn't.
- Local is slow on a laptop; production should answer in 300 ms.
- A debug header exists on local and must never appear in production.
Copying the collection per environment is how teams end up with three slightly different versions. Keep one, and let the environment decide.
1. Thresholds as variables
Add the same keys to every environment, with different values:
| Variable | Local | Staging | Production |
|---|---|---|---|
maxLatencyMs | 3000 | 1000 | 300 |
seededUserEmail | [email protected] | [email protected] | (empty) |
env | local | staging | production |
On a collection's or folder's Tests tab, add a check: Response time (ms) less than {{maxLatencyMs}}. Expected values in checks resolve variables, so the same check is strict in production and relaxed on your laptop.
In a script:
pm.test('fast enough for this environment', () => {
pm.expect(pm.response.responseTime).to.be.below(Number(pm.environment.get('maxLatencyMs')));
});2. Checks that only apply somewhere
Skip a test where it doesn't apply, and say so in the console:
const env = pm.environment.get('env');
if (env === 'production') {
pm.test('no debug header in production', () => {
pm.expect(pm.response.headers.has('X-Debug-Sql')).to.be.false;
});
} else {
console.log(`Skipping the production-only header check on ${env}`);
}Or the other way round, for seeded data:
const seeded = pm.environment.get('seededUserEmail');
if (seeded) {
pm.test('seeded user exists', () => {
const emails = pm.response.json().data.map((u) => u.email);
pm.expect(emails).to.include(seeded);
});
}Use an explicit variable such as env rather than guessing from the URL. URLs change; a variable says what you mean.
3. Requests that must not run in production
Some requests change data. Stop them in production with a pre-request script on their folder:
if (pm.environment.get('env') === 'production') {
pm.execution.setNextRequest(null); // end this iteration before anything is written
}The current request is still sent after its pre-request script, so put this on a harmless request at the top of the folder, such as a health check. Then no write request in that folder is reached. The safer habit is a separate folder for writes, and running only the read-only folder against production:
requestarium run-collection "Orders API" --folder "Read only" --env Production4. Different expected values
When the expected value itself differs, put it in the environment:
pm.test('pricing currency', () => {
pm.expect(pm.response.json().currency).to.equal(pm.environment.get('expectedCurrency'));
});The no-code version: JSON body $.currency equals {{expectedCurrency}}.
In CI
Pick the environment per job, and the checks follow:
requestarium run-collection "Orders API" --env Staging --junit staging.xml
requestarium run-collection "Orders API" --folder "Read only" --env Production --junit prod.xmlFor running the same collection against several environments in one workflow, see smoke tests after every deploy.