How to build an automated test suite in Postman, step by step.I am currently working on a web service. A tiny message board where users can post messages and retrieve messages that others have written. Like Twitter but less fancy and probably with less traffic. The basic functionality this service needs is posting, retrieving, editing and deleting messages. These functions are provided via an HTTP API.To test this API I have been using Postman. I have used Postman before in a rather ad-hoc fashion, but this time I wanted to build a proper, automated test suite. And I wanted to use the testing tools Postman provides instead of just the “send a request and see if the response looks alright” method I had been using before.
One of my testing scripts
So I did, and it worked out pretty well. I did have some problems during this process that eventually led to some insights. Some if these problems/insights were of the kind where I wished that someone had written a blog post about them so that I wouldn’t have had to to figure them out by myself. And that is how this blog came about. I definitely am not a Postman expert, so it should probably be considered a guide by a Postman newbie, for other Postman newbies.In this post I address a specific topic that gave me some trouble: the Postman environment variables. If what you need is a general introduction to Postman, their Getting Started and short blogpost about testing worked well for me.That’s it for this introduction, the rest of the post will be divided into suitable titled parts so that you can easily find what you actually came here looking for, promise!
Getting Postman scoped variables in input fields and code
The same variable name can be defined in different scopes, and which one is retrieved by variable.get is determined by their hierarchy: iterationData overshadows environment overshadows collection overshadows globals. This is of course why they are called “scopes.” Oh, and the entire hierarchy is per workspace.
Maybe JSON validation with Tiny Validator, maybe something else, who knows?