How to do Unit Testing using Postman

How to do API testing in Postman.

As we develop rest APIs, we need to test them properly before delivering to QA. So if you want to do pre QA testing then you can easily do that with help of postman.

Here I will tell you a step by step process of testing your API’s

Step 1 : Collection Creation

Open Postman and create a collection by highlighted icon as shown in image


Step 2: API C

Create an API request as show following

Screen Shot 2017-06-02 at 12.46.48 pm.png

  • Right now I have used GET request only for POST also I will explain later. Once you click on “Send” you will get response in below area.
  • Now Save this request using “Save” under that collection which you created
  • Create one or more API request also if you need.

POST request example

Screen Shot 2017-06-02 at 12.49.18 pm.png

Now we have two request in our collection as below

Screen Shot 2017-06-02 at 12.51.46 pm.png

Step 3: Environment Handling

As you can see both of request are pointing to my localhost so if I want to do testing of this API to other environment also I have to change url.

In order to avoid make url configurable create environment by clicking on manager environments as shown below.

Screen Shot 2017-06-02 at 12.53.41 pm.png

I have created two environment and added a variable specific to that

Screen Shot 2017-06-02 at 12.53.59 pm.png

Screen Shot 2017-06-02 at 12.58.52 pm.png

Screen Shot 2017-06-02 at 12.54.59 pm.png

Step 4: Environment Selection

Now I change my API url by using variable name as url and select environment from environmental dropdown.

Screen Shot 2017-06-02 at 1.00.36 pm.png

Screen Shot 2017-06-02 at 1.01.29 pm.png

As you can see I have added {{url}} in url location. If it is showing in orange color then variable is in environment else it will show in red color

Now Save.

Now you can easily test at both environment by just choosing environment we have added.

Step 5: Writing Test Case

You can also write test cases in postman as you can see there is a test tab under url of request click on that .

Screen Shot 2017-06-02 at 1.07.05 pm.png

Step 6: Postman Runner

Now consider we have 20-30 API so for testing one by one is a hectic process so we can automate that as following

  • Click on Runner button on top left, it will open a screen
  • Select your collection from option as below.
  • Screen Shot 2017-06-02 at 2.27.02 pm.png

Select your environment from option and click on run

Screen Shot 2017-06-02 at 2.30.09 pm.png

It will run all your api in same order as you have in your collection.


If you want to use some data from response of some api in request of another api you can set required data as global variable and use that variable as {{variable_name}}

postman.setGlobalVariable(“variable_key”, “variable_value”);

Use of this variable as


Download Postman from here.

If you have any qurie, Please comment.



One thought on “How to do Unit Testing using Postman

Add yours

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a website or blog at

Up ↑

%d bloggers like this: