How to set a Test in Postman with JavaScript Method?

We can set a Test in Postman with JavaScript method. In Postman, a test executes provided a Request is successful. This is because a test is created to include checkpoint and validate various parameters of the Response.

Tests implemented in the JavaScript method are written within the Tests tab.

Add the below JavaScript test −

tests["Verify Response Time"] = responseTime > 600

The tests is a variable of type array which can store data types- integer, string, Boolean and so on. Verify Response Time is the test name. The responseTime captures the time taken to obtain the Response.

Select a GET request and enter an endpoint then click on Send.

Click on the Test Results tab in Response.

The Test Results tab shows the test passed in green color. Response shows the code as 200 OK and time as 56ms (test checks if the Response time is greater than 30ms).