Bird
Raised Fist0
Postmantesting~20 mins

Defining mock responses in Postman - Practice Problems & Coding Challenges

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 Response Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Purpose of Mock Responses in Postman

What is the main purpose of defining mock responses in Postman?

ATo automatically generate API documentation
BTo simulate API responses without calling the actual server
CTo deploy APIs to production environments
DTo monitor live API traffic in real-time
Attempts:
2 left
💡 Hint

Think about why you might want to test an API before it is ready or available.

Predict Output
intermediate
2:00remaining
Output of a Mock Response Setup

Given this Postman mock response setup, what will be the HTTP status code returned when the mock is called?

Postman
{
  "name": "User Info Mock",
  "request": {
    "method": "GET",
    "url": "/user/info"
  },
  "response": {
    "status": 200,
    "body": "{\"name\": \"Alice\", \"age\": 30}",
    "headers": [{"key": "Content-Type", "value": "application/json"}]
  }
}
A500
B404
C401
D200
Attempts:
2 left
💡 Hint

Look at the status field inside the response object.

assertion
advanced
2:00remaining
Correct Assertion for Mock Response Body

Which Postman test script assertion correctly verifies that the mock response body contains the user's name as 'Alice'?

Postman
pm.test("User name is Alice", () => {
  const jsonData = pm.response.json();
  // Which assertion goes here?
});
Apm.expect(jsonData.name).to.eql('Alice');
Bpm.expect(jsonData.age).to.eql('Alice');
Cpm.expect(pm.response.text()).to.include('Bob');
Dpm.expect(jsonData.name).to.be.undefined;
Attempts:
2 left
💡 Hint

Check the property that holds the user's name and compare it to 'Alice'.

🔧 Debug
advanced
2:00remaining
Identify the Error in Mock Response Setup

What error will occur when this Postman mock response is called?

Postman
{
  "name": "Invalid Mock",
  "request": {
    "method": "POST",
    "url": "/submit"
  },
  "response": {
    "status": "two hundred",
    "body": "Success",
    "headers": [{"key": "Content-Type", "value": "text/plain"}]
  }
}
ANo error, mock returns status 200 automatically
BSyntaxError due to invalid JSON format
CRuntime error because status code must be a number, not a string
DTypeError because body must be an object, not a string
Attempts:
2 left
💡 Hint

Check the data type of the status field.

framework
expert
2:00remaining
Best Practice for Mock Response Matching in Postman

Which option describes the best practice to ensure Postman mock server returns the correct response when multiple mocks have similar request URLs?

AUse exact HTTP method and URL path matching with query parameters included if needed
BDefine mocks with only the URL path and ignore HTTP methods to simplify matching
CUse random response selection to test different scenarios automatically
DCreate one mock with a wildcard URL to handle all requests
Attempts:
2 left
💡 Hint

Think about how Postman decides which mock response to send when requests are similar.

Practice

(1/5)
1. What is the main purpose of defining mock responses in Postman?
easy
A. To permanently replace the real API endpoints
B. To speed up the actual server response time
C. To encrypt the API responses for security
D. To simulate server replies for testing without a real server

Solution

  1. Step 1: Understand mock response purpose

    Mock responses simulate server replies so you can test your app without needing the real server ready.
  2. Step 2: Eliminate incorrect options

    The incorrect options describe unrelated or incorrect uses: permanently replacing the real API endpoints, speeding up the actual server response time, or encrypting the API responses for security.
  3. Final Answer:

    To simulate server replies for testing without a real server -> Option D
  4. Quick Check:

    Mock responses = simulate server replies [OK]
Hint: Mocks simulate server replies for testing without real servers [OK]
Common Mistakes:
  • Thinking mocks speed up real servers
  • Confusing mocks with permanent API changes
  • Assuming mocks encrypt data
2. Which of the following is the correct way to define a mock response in Postman?
easy
A. Use the Postman console to manually type responses each time
B. Write JavaScript code in the request body to simulate response
C. Create a mock server and add example responses to requests
D. Change the API URL to a mock URL without setting up a server

Solution

  1. Step 1: Recall how mocks are defined in Postman

    Postman lets you create a mock server and attach example responses to requests to simulate replies.
  2. Step 2: Check other options for correctness

    Write JavaScript code in the request body to simulate response is incorrect because JavaScript in request body doesn't define mock responses. Use the Postman console to manually type responses each time is manual and not practical. Change the API URL to a mock URL without setting up a server is incomplete without mock server setup.
  3. Final Answer:

    Create a mock server and add example responses to requests -> Option C
  4. Quick Check:

    Mock response setup = mock server + examples [OK]
Hint: Mocks need a server plus example responses, not code in body [OK]
Common Mistakes:
  • Trying to write mock logic inside request body
  • Typing responses manually each time
  • Skipping mock server creation
3. Given a mock server with an example response for GET /users returning status 200 and body {"name": "Alice"}, what will Postman return when you send a GET request to /users on this mock server?
medium
A. Status 200 with body {"name": "Alice"}
B. Status 404 with empty body
C. Status 500 with error message
D. No response, request times out

Solution

  1. Step 1: Understand mock server behavior

    When a mock server has an example response for a request, it returns that response exactly when the request matches.
  2. Step 2: Match request and response

    The GET /users request matches the example with status 200 and body {"name": "Alice"}, so that response is returned.
  3. Final Answer:

    Status 200 with body {"name": "Alice"} -> Option A
  4. Quick Check:

    Mock returns example response = status 200 + body [OK]
Hint: Mock returns example response matching request path and method [OK]
Common Mistakes:
  • Expecting error or timeout instead of example response
  • Confusing status codes returned by mock
  • Assuming mock returns empty or default response
4. You created a mock server but when sending requests, you get 404 errors. What is the most likely reason?
medium
A. Postman does not support mock servers for GET requests
B. No example response matches the request method and URL
C. Your internet connection is down
D. The mock server URL is misspelled in the request

Solution

  1. Step 1: Analyze 404 error cause in mock servers

    404 means not found. In mocks, this usually means no example response matches the request method and URL.
  2. Step 2: Check other options

    The mock server URL is misspelled in the request could cause errors but 404 specifically means no matching example. Your internet connection is down causes no response, not 404. Postman does not support mock servers for GET requests is false; Postman supports GET mocks.
  3. Final Answer:

    No example response matches the request method and URL -> Option B
  4. Quick Check:

    404 in mock = no matching example response [OK]
Hint: 404 means no matching example response for request [OK]
Common Mistakes:
  • Assuming 404 means internet or URL typo always
  • Thinking Postman mocks don't support GET
  • Ignoring example response matching
5. You want to test how your app handles different user roles using Postman mock responses. Which approach is best to define mock responses for this scenario?
hard
A. Create multiple example responses for the same request with different response bodies and use request headers to select them
B. Create one example response and manually edit it each time you test a different role
C. Use a single example response with all roles combined in one body
D. Change the mock server URL for each user role

Solution

  1. Step 1: Understand testing multiple scenarios with mocks

    To test different user roles, you need different responses for the same request that vary by role.
  2. Step 2: Use multiple examples with header matching

    Postman allows multiple example responses for one request. You can use request headers to select which example to return, simulating different roles.
  3. Step 3: Eliminate other options

    Create one example response and manually edit it each time you test a different role is manual and inefficient. Use a single example response with all roles combined in one body mixes roles confusingly. Change the mock server URL for each user role is unnecessary and complex.
  4. Final Answer:

    Create multiple example responses for the same request with different response bodies and use request headers to select them -> Option A
  5. Quick Check:

    Multiple examples + headers = role-based mock responses [OK]
Hint: Use multiple examples with headers to simulate roles [OK]
Common Mistakes:
  • Editing one example repeatedly
  • Combining all roles in one response
  • Changing mock server URL unnecessarily