Write your first test

API tests are a way to ensure that your API is behaving as you expect it to. For example, you might write a test to validate your API's error handling by sending a request with incomplete data or wrong parameters. You can write tests for your Postman API requests in JavaScript and add them to individual requests, collections, and folders in a collection. Postman includes code snippets you can add and then change to suit your test logic.

To write a test, do the following:

  1. Go to the request you made in sending your first request.

  2. In the request, go to the Scripts tab, then select the Post-response tab.

  3. In the snippet section to the right, select the snippet Status code: Code is 200. This will enter the following test code:

    pm.test("Status code is 200", function () {
  4. Select Send.

After the request runs, the test will run. Go to the Test Results section of the response to review the results of your test.

To learn more about writing tests, go to Write scripts to test API response data in Postman.

Last modified: 2023/07/26