Search This Blog
Hello there, warm Welcome :-) I am trying to share the knowledge and cool things I learnt during my QA journey!! I hope you find something interesting here :-)
Featured
- Get link
- X
- Other Apps
How to mock the APIs and how is that helpful?
When and how to use Mock Servers and how to set up a Mock server in Postman?
What is a Mock Server?
During your API Testing journey, you cannot wait every time for your API to be completely ready.
We might have the API documentation with the sample responses. So what do we? Using the sample response we can create mock APIs and that endpoint can be used for your testing purposes.
You might have heard the term “Mock servers”, it is nothing but a single base URL with multiple API endpoints configured to return the specified response every time. So every time you hit the specific endpoint, the same response is returned.
How is that helpful?
- We can analyze the response body and understand what is expected in the body
- We can start writing the assertions for our response body
- This helps to continue development even when an external service fails.
- This avoids data sharing and supports to test the endpoints individually.
To know more about Mock servers please check here.
How to create a “Mock Server” using Postman:
There are few ways of initiating the process:
Option 1: Clicking the “New” at the top
Option 2: Click the three dots next to the collection, and select “Mock Collection”
Option 3: Navigating the “Mock Servers” tab in the left pane.
All the options will land-up in the mock server page.
Prerequisite:
You need to add “Example” ”response to the request. To know more about it read here.
What next?
- By selection any of the listed options above, land on the “Create Mock server” page. If you are doing using the existing collection select it, and follow the instructions as below:
2. Tada, the Mock server is now created.
3. New environment with the name of mock server is created and the mockURL is added as a variable “url” automatically.
4. Now move back to the collection. Instead of the baseURL, you can replace it with the mock server URL.
5. If you hit send, the same response is returned for every run, based on the example response added.
6. Now if the server is unavailable, this request will respond with the constant response.
Based on different use cases, the API responses are mocked and used accordingly.
For more details refer: https://www.mock-server.com
I hope this was useful to you. See you soon in a another blogpost soon!!
Popular Posts
What are the different types of variables in Postman? How and when to use them?
- Get link
- X
- Other Apps
Comments
Post a Comment