Bird
Raised Fist0
Postmantesting~20 mins

Creating mock servers in Postman - Practice Exercises

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Mock Server Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Purpose of Mock Servers in API Testing

Why do testers use mock servers when testing APIs?

ATo speed up the actual API server by offloading requests
BTo simulate API responses when the real API is unavailable or incomplete
CTo permanently replace the real API in production environments
DTo automatically generate API documentation without manual input
Attempts:
2 left
💡 Hint

Think about situations when the real API is not ready but testing must continue.

Predict Output
intermediate
1:30remaining
Mock Server Response Matching

Given a Postman mock server with this example request and response setup:

{
  "method": "GET",
  "url": "/users/123"
}

What response will the mock server return when a GET request is made to /users/123?

Postman
GET /users/123 HTTP/1.1
Host: mockserver.postman.com
AAn empty response with status 204 No Content
BA 404 Not Found error because the mock server does not support GET requests
CA 500 Internal Server Error due to missing authentication
DThe predefined example response for GET /users/123
Attempts:
2 left
💡 Hint

Mock servers return the example response matching the request method and URL.

assertion
advanced
2:00remaining
Validating Mock Server Response Status Code

In Postman test scripts, which assertion correctly checks that the mock server response status code is 200?

Postman
pm.test("Status code is 200", () => {
    // Fill in assertion here
});
Apm.expect(pm.response.status).toBe(200);
Bpm.response.status === 200;
Cpm.response.to.have.status(200);
Dpm.response.statusCode(200);
Attempts:
2 left
💡 Hint

Use Postman's built-in assertion syntax for status codes.

🔧 Debug
advanced
1:30remaining
Troubleshooting Mock Server URL Mismatch

A tester created a mock server in Postman but receives 404 errors when sending requests. Which is the most likely cause?

AThe request URL path does not exactly match any example request path in the mock server
BThe mock server requires an API key but the request includes none
CThe mock server is offline and cannot respond to requests
DThe request method is POST but the mock server only supports GET
Attempts:
2 left
💡 Hint

Mock servers match requests by method and exact URL path.

framework
expert
2:30remaining
Configuring Postman Mock Server for Dynamic Responses

Which Postman feature allows a mock server to return different responses based on request parameters or headers?

AUsing multiple examples with matching request query parameters or headers to select the response
BWriting JavaScript code inside the mock server to dynamically generate responses
CEnabling the mock server's AI response generator to create varied outputs
DConfiguring the mock server to forward requests to the real API for dynamic data
Attempts:
2 left
💡 Hint

Postman mock servers select responses based on matching request details in examples.

Practice

(1/5)
1. What is the main purpose of creating a mock server in Postman?
easy
A. To monitor live API traffic
B. To deploy the real API to production
C. To write code for the backend server
D. To simulate API responses without needing the actual backend

Solution

  1. Step 1: Understand what a mock server does

    A mock server simulates API responses so developers can test without a real backend.
  2. Step 2: Compare options with this purpose

    Only To simulate API responses without needing the actual backend describes simulating responses without the actual backend.
  3. Final Answer:

    To simulate API responses without needing the actual backend -> Option D
  4. Quick Check:

    Mock server purpose = simulate API responses [OK]
Hint: Mock servers simulate, not deploy or write backend code [OK]
Common Mistakes:
  • Confusing mock servers with real backend deployment
  • Thinking mock servers monitor live traffic
  • Assuming mock servers generate backend code
2. Which of the following is the correct step to create a mock server in Postman?
easy
A. Select a collection, then click 'Mock Server' and configure settings
B. Write backend code and deploy it to Postman
C. Create a new environment and add variables
D. Run the collection in the runner without any setup

Solution

  1. Step 1: Identify how to create a mock server

    In Postman, mock servers are created from collections by selecting 'Mock Server' option.
  2. Step 2: Check which option matches this process

    Select a collection, then click 'Mock Server' and configure settings correctly describes selecting a collection and clicking 'Mock Server'.
  3. Final Answer:

    Select a collection, then click 'Mock Server' and configure settings -> Option A
  4. Quick Check:

    Create mock server = select collection + 'Mock Server' [OK]
Hint: Mock servers start from collections, not environments or code [OK]
Common Mistakes:
  • Confusing environment setup with mock server creation
  • Thinking mock servers require backend code
  • Trying to run collections without mock server setup
3. Given this Postman mock server setup:
{
  "method": "GET",
  "url": "/user/123",
  "response": {
    "status": 200,
    "body": "{\"id\":123, \"name\": \"Alice\"}"
  }
}

What will the mock server return when a GET request is made to /user/123?
medium
A. HTTP 404 Not Found error
B. HTTP 200 with body {"id":123, "name": "Alice"}
C. HTTP 500 Internal Server Error
D. No response because URL is incorrect

Solution

  1. Step 1: Analyze the mock server response setup

    The mock server is set to respond to GET /user/123 with status 200 and JSON body {"id":123, "name": "Alice"}.
  2. Step 2: Match the request and response

    A GET request to /user/123 matches the mock setup, so it returns status 200 and the JSON body.
  3. Final Answer:

    HTTP 200 with body {"id":123, "name": "Alice"} -> Option B
  4. Quick Check:

    Matching URL + method = 200 + JSON body [OK]
Hint: Match method and URL exactly to get mock response [OK]
Common Mistakes:
  • Assuming 404 if unsure about URL matching
  • Confusing status codes for mock responses
  • Ignoring the method type in mock setup
4. You created a mock server but when sending requests, you always get a 404 error. What is the most likely cause?
medium
A. The request method is POST but mock expects GET
B. The mock server is down due to network issues
C. The mock server URL does not match the request URL
D. The collection has no example responses defined

Solution

  1. Step 1: Understand 404 in mock server context

    A 404 means the mock server did not find a matching request URL and method.
  2. Step 2: Identify common causes for 404

    If the request URL does not exactly match the mock server URL, 404 occurs. This is the most common cause.
  3. Final Answer:

    The mock server URL does not match the request URL -> Option C
  4. Quick Check:

    404 error = URL mismatch [OK]
Hint: Check exact URL match to fix 404 errors on mock servers [OK]
Common Mistakes:
  • Assuming network issues cause 404
  • Forgetting to add example responses in collection
  • Ignoring HTTP method mismatch
5. You want to create a mock server that returns different responses based on query parameters. Which approach should you use in Postman?
hard
A. Create multiple example requests in the collection with different query parameters and responses
B. Write JavaScript code in the mock server to handle query parameters
C. Use environment variables to change the mock server URL dynamically
D. Create separate mock servers for each query parameter value

Solution

  1. Step 1: Understand how Postman mock servers handle query parameters

    Postman mock servers match requests to example requests including query parameters to return the correct response.
  2. Step 2: Identify the best way to handle different query parameters

    Creating multiple example requests with different query parameters and responses allows the mock server to return varied responses.
  3. Final Answer:

    Create multiple example requests in the collection with different query parameters and responses -> Option A
  4. Quick Check:

    Multiple examples = varied responses by query [OK]
Hint: Use multiple examples with query params for varied mock responses [OK]
Common Mistakes:
  • Thinking mock servers run custom code
  • Trying to change mock URL with environment variables
  • Creating many mock servers instead of examples