- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set Tests using Functional Method in Postman?
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.
- Related Articles
- How to set Multiple Tests for a Request in Postman with JavaScript Method?
- How to set a Test in Postman with JavaScript Method?
- Executing Tests on Cookies in Postman
- How to group selected tests from a set of tests in pytest?
- How to set a global variable in Postman?
- How to set Test and Collection Runner in Postman?
- How to Run WebDriver in Headless Mode using Postman?
- How to run a selected test from a set of tests in pytest?
- How to run Selenium tests on Chrome Browser using?
- How to Generate Newman Reports on Jenkins using Postman?
- How to Run Postman Collection on Jenkins using Newman Commands?
- How to Import Collection in Postman?
- How to Monitor Collections in Postman?
- How to use Sessions in Postman?
- How to Manage Cookies in Postman?
