Using the runner to test the APIs

The Postman team built a runner tool that automatically tests and runs your APIs so that you can – quite literally – sit back and watch your API test itself. Furthermore, you can use scripts to build integration test suites, pass data between API requests, and build workflows that mirror your actual API use cases. 

The runner feature requires at least one test to be associated with the request so that it can assert the result. It is possible to access the runner interface of Postman by clicking on the Runner button (shown in the yellow rectangle in the following screenshot), which can be found in the top-left corner of the screen, and selecting the collection you want to run:

Postman also allows us to integrate these functionalities using the CLI. The development team published an npm package to execute the runner in a localhost environment. It is possible to install this package on your local machine using the following command:

npm install -g newman

After that, it is possible to execute the runner on a specific collection by passing the JSON file that represents the collection and then executing the preceding command. It is possible to export a collection by clicking on the three points next to the collection and clicking on the Export option:

Then, we can proceed by executing this command on the file:

newman run examples/sample-collection.json

The resulting execution will look something similar to the following:

This implementation provides a single and detailed response of each request that was tested and a final report that shows all the information related to the tests. This approach is really useful when we want to integrate Postman's testing capabilities into a continuous integration pipeline. All we need to do is install the newman tool on our server and add the path of the collection.

In the next section, we will learn how to use the OpenAPI Specification (described in the previous chapter) to automatically generate a Postman collection. 

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

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