How to use example to do tests

Hi everyone,

I’m trying to use the “Examples” feature in Postman to create different responses for a single GET request, where each example corresponds to a different HTTP status code (e.g., 200, 400, 404, etc.).

However, when I run the request and try to test it, it seems the examples are not automatically triggered or tested. I currently have to manually create separate copies of the same GET request, change the parameters to simulate different responses, and then run tests on each one individually.

Is there a way to automatically run tests against all the examples without creating multiple request copies?
Or maybe a better way to use examples in combination with tests?

Thanks a lot for your help!

As you can see, in GET /FirmwareHub/maj-ota/:model/:version, I have several examples created. However, when I run the request and launch the tests, none of the examples are automatically triggered or tested.

The examples just return data based on what was sent.

You can’t just hit each example without sending the requisite data to trigger that sample.

The easiest method is what you have already found out.

You will need to have multiple copies of the GET request. One for each scenario you want to test. You would normally rename the request to something appropriate that relates to the specific test.

Another options is with a data driven approach that hits the same GET request with different properties each time. You will also need to include the assertions in the data file, as the assertions will need to be different each time as well. This is slightly more complex to run and will also need the Collection Runner to execute the requests\collection. (As data files only work with the Collection Runner).