Test and Collection Runner in Postman


We can have checkpoints to verify the Response from a request. This is done by adding scripts in the Tests tab. These scripts get executed if the request has executed successfully.

The scripts added under the Tests tab are developed in JavaScript. After a request has been sent and a Response is received, the outcome of these test scripts are reflected in the Test Results tab in the Response. The passed tests are marked ingreen and the failed tests are in red.

Input the below tests in 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 array type which can store values of data types- integer,string, Boolean and so on. The Status Code should be 200 and Response time lesser than 10ms are test names. The responseCode.code is the code yielded in the Response and the responseTime is the time consumed to obtain the Response.

Select a method, type an URL and click on the Send button.

Response code obtained is 200 OK and response time is 129ms (the second test checks if the Response time is lesser than 10ms). The Test Results(1/2) reflects the fact that one test out of the two has passed.

Let us take a Collection with more than one request and execute them via the Collection Runner.

Step 1 − Click on the Runner menu.

Step 2 − The Collection Runner pop-up comes up.

Step 3 − Select the name of the Collection from the Choose a collection or folder segment.

Step 4 − Choose an Environment and input the number of iterations and request delay time.

Step 5 − In case the data for the requests is from a file, we have to choose the file type from the Data field and then click on Run Collection1.

Step 6 − Run Results section of the Collection Runner window is displayed. The Environment, Collection name and passed/failed numbers are available on the top of the window. For individual requests, the Response status code, time taken, size, and tests (Status Code is 200) information are visible.

Published on 03-Aug-2021 14:36:54