How to set Test and Collection Runner in Postman?


We can add test verifications to the Response obtained from a request with the help of scripts. These scripts are incorporated in the Tests tab. The tests only get executed provided the request is successful.

A test developed under the Tests tab is written in JavaScript. Once a request is sent, a Response is obtained along with the test results in the Test Results tab. Tests which have passed are marked in green and the failed ones are marked in red.

Add the below JavaScript verifications within the Tests tab −

tests["Status Code should be 200"] = responseCode.code === 200
tests["Response time lesser than 10ms"] = responseTime<10

The tests is a variable of type array which can have values with data types- integer, string, Boolean and so on. The Status Code should be 200 and Response time lesser than 10ms are test names. We should give a meaningful name to the test. The responseCode.code is the code obtained in the Response and the responseTime is the time taken to get the Response.

Choose an HTTP method and enter an URL, then click on Send.

Response code obtained is 200 OK and response time is 129ms (the second test verifies if the Response time is lesser than 10ms). The above test shows the Response with Test Results(1/2) meaning one out of the two tests got passed. The first test passed and the second one failed with the Assertion error.

Let us take a Collection having multiple requests and execute them with the help of the Collection Runner.

Step 1 − Click on the Runner menu in the Postman application.

Step 2 − Collection Runner window opens up.

Step 3 − Choose the Collection name from the Choose a collection or folder section.

Step 4 − Choose an Environment if the requests in the Collection need to be executed in a particular Environment. Enter the number of iterations for the request and delay time for the requests.

Step 5 − If the data for the requests are from a file, we can select the file type from the Data field. Finally, click on Run Collection1.

Step 6 − The Run Results section of the Collection Runner window opens up. The Environment, Collection name and passed/failed count are displayed at the top. For each request, the Response status code, time taken, payload size, and test verifications are populated.

We will find in the below image that the test – Status Code is 200 has been executed for all the requests in both the iterations. In case there is no test implemented for a particular request, then it shall display the message as - This request does not have any tests.

Published on 03-Aug-2021 13:27:24