# How to set Tests using Functional Method in Postman?

PostmanREST APISOAP API

We can set Tests using the Functional method in Postman. A test in Postman gets executed only if a Request is successful. In case a Response does not get generated, the test does not to validate it.

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

Add the following verification using the Functional method within the Tests tab −

pm.test["Status Code is 401"], function(){
pm.response.to.have.status(401)
})

Here, pm.test is the function. Status Code is 401 is the test name which shall be displayed in the Test Result tab after execution. The pm.response is used for getting the Response and adding assertions on it to verify.

Select the GET method and enter an endpoint then click on Send.

Click on the Test Results tab in Response.

The Test Results tab shows the test in red as the verification failed. The Test Results (0/1) means zero out of the one test passed. Response shows the status as 200 OK (but the test checks if the response code is 401).

Hence the test failed along with the Assertion error.

Published on 25-Jun-2021 12:59:10