Introduction
Developers can easily create, share, test, and document APIs with Postman, an API client. Users are given the ability to generate, store, and read both simple and complicated HTTP/s requests as well as their responses in order to achieve this. It is a program that offers a graphical user interface for testing APIs. The collection feature and the ability to construct several testing settings are a couple of Postman's benefits.

To write postman tests verify that your API is operating as intended, that service integrations are reliable, and that any modifications haven't harmed already-existing functionality. JavaScript can be used to create test scripts for Postman API queries. When something goes wrong with your API project, test code might also help with the debugging process. You could, for instance, create a test to verify your API's error handling by submitting a request with inaccurate or incomplete information.
Individual requests, collections, and folders in a collection can all have tests added to them. You can add code snippets to Postman and then modify them to fit your test logic.
Write test scripts in postman
Dynamic variables, test assertions on response data, and data passing across requests are all capabilities of test scripts.
Step 1: Enter your JavaScript manually or choose Snippets adjacent to the code editor in the Tests tab for a request.
Step 2: Tests are run upon the reception of the response. When you choose Send, Postman executes your test script upon the API response data's return.
Validating responses
You can use the pm. response object in a test to verify the information a request returns. Create tests by giving them a name and a function that produces a boolean (true or false) value indicating whether the test passed or failed using the pm. test function.
A text string that will show in the test result output is the first parameter for the. test method.
To run your request and display the Test Results in the response box, select Send. Additionally, you can see how many tests were passed, skipped, and failed.
Your test result messages will have a different format if you use the pm. expect syntax. To write your tests in a comprehensible style that works with your application and testing logic, you can use a variety of syntax options.
Snippets are still another approach. There is a collection of frequently used test code snippets in the Snippets section. Once you choose one, it will be added to your editor. Beginning your scripts more quickly is possible with snippets.