Writing automated API tests
Postman allows us to add tests that run automatically after an API response is returned from the server. This can be done through the Tests tab in the Postman request dashboard. We will be using the following three GitHub API requests in this section to help us set up and understand automated API response validation:
- Create a new repository
- Get a repository by name
- Delete a repository by name
In the next section, let us review how to use snippets to speed up our test automation process.
Using snippets for asserting an API response
Postman comes with pre-defined JavaScript test scripts in the form of code snippets that can directly be used in our tests. Let us start by adding snippets for some of the basic checks performed on an API response. Snippets are shown on the right pane next to the various tabs on the request dashboard.
Every API test requires the validation of the status of an API response, and Postman provides a...