Executing Postman request tests locally

So far, in Postman, we have created a collection, in which there are two requests that contain the parameters and tests of our APIs that are to be tested. To test the proper functioning of the APIs with their parameters and tests, we must now execute our requests that are in Postman. Note that it will only be at the end of this execution that we will know whether our APIs correspond to our expectations.

To execute a Postman request, we will perform the following actions:

  1. You must first choose the desired environment.
  2. Click on the Send button of the request, as shown in the following screenshot:

  1. In the Body tab, we can then view the content of the query response, and if we want to display it in JSON format, we can choose the display format. The following screenshot shows the response of the request displayed in JSON format:

  1. The Test Results tab displays the results of the execution of the tests that we previously wrote, and in our case, the four tests have been executed correctly—they are all green, as shown in the following screenshot:

In the preceding screenshot, we can see that the return code of the Postman request is equal to 200, which corresponds to the request's successful execution return code, and its execution time of 23 ms, which is below the threshold (400 ms) that I set for myself as an example.

In the event that one of the tests fails, it will be displayed in red in order to clearly identify it. An example of a failed test is shown in the following screenshot:

We have just seen the execution of a Postman request to test an API, but this execution is only for the current request. If we want to execute all Postman requests in a collection, we can use the Postman Collection Runner.

The Postman Collection Runner is a Postman feature that automatically executes all the requests in a collection in the order in which they have been organized.

You can learn more in the Collection documentation by visiting https://learning.getpostman.com/docs/postman/collection_runs/starting_a_collection_run/.

The following two screenshots show the Runner execution steps, in which we choose the collection to execute, the environment, and the number of iterations. To start its execution, we click on the Run DemoBook button:

And so, in the Collection Runner screen, we can see the test execution result of all the requests in the collection, as shown in the following screenshot:

The documentation for the Collection Runner can be found at https://learning.getpostman.com/docs/postman/collection_runs/intro_to_collection_runs.

In this section, we have learned how to execute Postman requests in order to test an API in a unitary way, before executing all the requests in the collection using the Postman Collection Runner. In the following section, we will introduce Newman, which will allow us to automate the execution of Postman tests.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.183.172