How to Setup Postman Mock Server

Fiko Borizqy
4 min readAug 8, 2021

--

source : https://sudonull.com/post/8084-Mock-server-to-automate-mobile-testing

When you’re developing a project with a third party for the API service, you must need their development / sandbox site to develop and run test instead of running the test using their (3rd party) production site. But, sometimes their sandbox is not ready or in the worst case they have no sandbox site to run the test.

You can use postman to create the mock server to run test base on the case you’d like to develop. Postman provides this feature free (of course it has limitation, mate), for more information of postman mock server limitation you can read on this page https://www.postman.com/pricing/. Okay, be ready for the steps (I’m using Postman v8.10.0) :

1. Prepare Collection

Create new collection

Create new collection if you have no collection on your workspace. You may rename your new collection, in this case I rename my collection to “Mock Server”.

Rename the collection Name

2. Prepare Environment

2.1. Create new Environment

You need to create new environment to handle the address. It’s not a mandatory actually, but it will make your development much easier, so just do this step on your own.

Create new environment

2.2. Create Environment Variable

In this case i’m creating base_url, so what is it? once you created a new mock server, you will have endpoint URL. We need to store this URL so you don’t have to change the endpoint URL on every request.

You don’t have to have base_url as the variable, you may use whatever you like to use. Just leave empty for the initial value & current value, why? because we haven’t setup the mock server.

Create environment variable

3. Prepare Mock Up Server

3.1. Create Mock Server

Simply just go to mock server menu.

Create Mock Server

Then configure the mock server to match with the environment we previously created.

Configure Mock Server

as the result, you will have mock server URL as your endpoint URL address.

Mock Server Result

3.2. Setup base_url

In Step 2.2 we created base_url environment variable, copy mock server URL as a value to this variable.

Setup mock server URL

4. Prepare Request

4.1. Create Request

Then once collection is ready, prepare new / existing request to handle the request. in this case, I’m creating new request called “Authentication”.

Create new request

4.2. Setup Request

Then once you’ve finish creating new request, you need to setup the request. in this case, I’m creating such as a login feature by sending username & password.

Setup login endpoint

4.3. Setup Response Example

This is the main point, you need to create response example for the request.

Add new example

Then setup the response (body & header).

Setup Response

5. Test it

In this test case I hit the API by postman & terminal (just to make sure it works perfectly just like what I want).

Testing

--

--

Fiko Borizqy
Fiko Borizqy

Written by Fiko Borizqy

I wrote these tutorials for myself in future when I forget for the next steps.

No responses yet