Test multiple responses for one endpoint

I’m trying to create tests for several different response statuses that one GET call can return (200, 206, 400, 403, 404, etc.). I can trigger each response by making the call with specific input.

My question is, is there a way to hit a specific endpoint several times in one test run with different input each time and a different assertion each time?

I know you can loop over the same endpoint with “postman.setNextRequest()”, but as far as I can figure out it will then just uses the same input and assertion each time.

One thing I considered is duplicating the call several times in my collection, but for maintainability (and my own sanity) I would like to prevent that.

Hi @paulgroothuisrvc

So, the easiest option that I have found is to create a JSON data file that can be added as a Data file using the Collection Runner

Sample Data/Data File:

“url”: “https://api.com/test1/”,
“expected_status_code”: 200
“url”: “https://api.com/test2/”,
“expected_status_code”: 201
“url”: “https://api.com/test3/”,
“expected_status_code”: 202

Then in your one Request you have the option to either drive using the Data file that automatically goes through each iteration and you use the url from the JSON:

Pre Requests:

pm.variables.set(“url”, pm.iterationData.get(“url”);

POST: {{url}}


let status = pm.interationData.get("expected_status_code);
pm.test("Status is " + status e, function () {

There is also the option to have the JSON as a CollectionVariable but the coding would be more complicated (but would also mean that you could rerun without having to identify the Data file every time that you want to run.

Hope that helps!

1 Like