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 postman.com/pricing. Okay, be ready for the steps (I’m using Postman v8.10.0) :
1. Prepare 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".
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.
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.
3. Prepare Mock Up Server
3.1. Create Mock Server
Simply just go to mock server menu.
Then configure the mock server to match with the environment we previously created.
as the result, you will have mock server URL as your endpoint URL address.
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.
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".
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.
4.3. Setup Response Example
This is the main point, you need to create response example for the request.
Then setup the response (body & header).
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).
Did you find this article valuable?
Support Fiko Borizqy by becoming a sponsor. Any amount is appreciated!