Test Automation in Postman

You can use Postman to write test scripts for REST services. The free version of Postman contains all the functionality you need. The number of API calls per month (1000) could be a limitation when testing intensively.

I’ll skip the basics of manual testing via Postman. As you can see in the screenprint below, additional tests can be added via the Tests tab. This way we can automate our test effort.

In this case we called a get method on an API Management endpoint. We entered a test to see if we received a response within 200 milliseconds. This is a standard test that we can drag and drop from the window on the right-hand side. This way we could also add a test to check if we actually received a successful Http 200 response. In tab Test Results of our output, we see that our test has passed. Simple, but powerful.

More interesting tests are the JSON Value Check and Schema Validation. Below is an example of the JSON Value check and the relevant part of the response.

pm.test("Test Administration", function () 
{    var jsonData = pm.response.json();   

To perform a schema validation, we first need to add an Environment (for example Test) and then add a variable CustomerSchema. We don’t want to add the Customer schema to each individual test. That’s why we add a variable first. We can use multiple environments so that we can – as an example – define different addresses for Test, Accept and Prod. To be able to select the variable in a testcase, we will have to select the environment from the drop-down box at the top right hand side of the Postman window. Now we can reference the variable in the test script:

The last tip is to add multiple tests to a collection and then run all tests within the collection to see the test results. If you use a Team Collection, you can even share the test scripts with your fellow test team members.