Bird
Raised Fist0
Postmantesting~20 mins

Mock vs stub comparison in Postman - Practice Questions

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 vs Stub Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Difference between mock and stub in API testing

Which statement best describes the difference between a mock and a stub in API testing using Postman?

AA stub provides predefined responses to API calls without behavior verification, while a mock also verifies that the API calls were made as expected.
BA mock only provides static responses, whereas a stub dynamically changes responses based on request data.
CA stub verifies the sequence of API calls, but a mock only returns fixed responses without verification.
DMocks and stubs are identical; both only simulate API responses without any verification.
Attempts:
2 left
💡 Hint

Think about whether the tool checks if the API was called correctly or just returns data.

Predict Output
intermediate
2:00remaining
Postman mock server response behavior

Given this Postman mock server setup that returns a fixed JSON response, what will be the response body when a GET request is sent?

Postman
{
  "message": "Hello from mock",
  "status": 200
}
A
{
  "error": "Not found",
  "status": 404
}
B
{
  "message": "Hello from stub",
  "status": 200
}
C
{
  "message": "Hello from mock",
  "status": 200
}
DEmpty response with status 204
Attempts:
2 left
💡 Hint

The mock server returns the predefined response exactly as configured.

assertion
advanced
2:00remaining
Valid assertion for verifying stub response in Postman test script

Which Postman test script assertion correctly verifies that the stubbed API response contains a 'userId' field with value 5?

Postman
pm.test("Check userId is 5", () => {
  // assertion here
});
Apm.expect(pm.response.json().userId).to.eql(5);
Bpm.expect(pm.response.userId).to.equal(5);
Cpm.expect(pm.response.json.userId).toBe(5);
Dpm.expect(pm.response.body.userId).to.eql(5);
Attempts:
2 left
💡 Hint

Remember to parse JSON and use the correct assertion method in Postman.

🔧 Debug
advanced
2:00remaining
Identify the error in Postman mock test script

What error will this Postman test script produce when run against a mock server response?

Postman
pm.test("Response has status 200", () => {
  pm.expect(pm.response.status).to.equal(200);
});
ASyntaxError: Unexpected token '.'
BAssertionError: expected 200 to equal 200
CNo error, test passes successfully
DAssertionError: expected 'OK' to equal 200
Attempts:
2 left
💡 Hint

Check how to access the response status code in Postman scripts.

framework
expert
3:00remaining
Best practice for combining mocks and stubs in Postman API testing

Which approach best uses both mocks and stubs in Postman to test an API that depends on an external service?

AUse only mocks for both returning data and verifying calls, ignoring stubs completely.
BUse a stub to return fixed data for the external service and a mock to verify the API calls to that service during integration tests.
CUse stubs to verify API call sequences and mocks to return dynamic responses based on request data.
DUse mocks to simulate the external service responses without any verification, and stubs to check call correctness.
Attempts:
2 left
💡 Hint

Think about separating response simulation and call verification roles.

Practice

(1/5)
1. Which statement best describes the difference between a mock and a stub in Postman testing?
easy
A. Mocks and stubs both return fixed responses without behavior simulation.
B. Mocks simulate API behavior with dynamic responses; stubs return fixed responses.
C. Stubs simulate API behavior with dynamic responses; mocks return fixed responses.
D. Mocks and stubs are the same and can be used interchangeably.

Solution

  1. Step 1: Understand mock behavior in Postman

    Mocks simulate real API behavior and can return different responses based on requests, making them dynamic.
  2. Step 2: Understand stub behavior in Postman

    Stubs provide fixed, predefined responses to replace real API calls, without simulating behavior.
  3. Final Answer:

    Mocks simulate API behavior with dynamic responses; stubs return fixed responses. -> Option B
  4. Quick Check:

    Mock = dynamic, Stub = fixed [OK]
Hint: Mocks are dynamic; stubs are fixed response tools [OK]
Common Mistakes:
  • Confusing mocks as fixed response tools
  • Thinking stubs simulate behavior dynamically
  • Believing mocks and stubs are identical
  • Assuming stubs can replace mocks fully
2. Which of the following is the correct way to create a stub in Postman?
easy
A. Create a collection with fixed example responses and disable real API calls.
B. Use Postman Mock Server with multiple dynamic response rules.
C. Write JavaScript code to simulate API logic inside Postman tests.
D. Use Postman monitors to generate live API responses.

Solution

  1. Step 1: Identify stub creation method

    Stubs are created by defining fixed example responses in a Postman collection to replace real API calls.
  2. Step 2: Eliminate other options

    Mocks use dynamic rules, JavaScript simulates logic but is not stub creation, and monitors check live APIs.
  3. Final Answer:

    Create a collection with fixed example responses and disable real API calls. -> Option A
  4. Quick Check:

    Stub = fixed examples in collection [OK]
Hint: Stubs use fixed examples, not dynamic rules [OK]
Common Mistakes:
  • Confusing mocks with stubs in creation steps
  • Thinking JavaScript test scripts create stubs
  • Using monitors as stubs
  • Assuming dynamic responses are stubs
3. Given a Postman mock server configured to return a 200 status with body {"success": true} for GET /user, what will happen if you replace it with a stub that always returns {"success": false} for the same request?
medium
A. Tests expecting success will fail because stub returns fixed failure response.
B. Tests will pass because stub simulates the same dynamic behavior as mock.
C. Tests will fail due to syntax errors in stub configuration.
D. Tests will pass because both mock and stub return 200 status.

Solution

  1. Step 1: Analyze mock server response

    The mock server returns {"success": true} dynamically for GET /user, indicating success.
  2. Step 2: Analyze stub response effect

    The stub always returns {"success": false}, a fixed failure response, which differs from mock.
  3. Final Answer:

    Tests expecting success will fail because stub returns fixed failure response. -> Option A
  4. Quick Check:

    Stub fixed failure ≠ mock success [OK]
Hint: Stub fixed response can break tests expecting mock's dynamic success [OK]
Common Mistakes:
  • Assuming stub matches mock dynamic behavior
  • Ignoring response body differences
  • Thinking status code alone determines test pass
  • Confusing syntax errors with logic errors
4. You created a Postman mock server but your tests always receive the stub's fixed response instead of the mock's dynamic response. What is the most likely cause?
medium
A. Postman does not support mock servers with dynamic responses.
B. The mock server is not enabled in Postman settings.
C. The mock server URL is incorrectly set to the stub server URL in the tests.
D. The stub server is down, causing fallback to mock responses.

Solution

  1. Step 1: Identify URL configuration issue

    If tests receive stub responses instead of mock, likely the test requests use the stub server URL mistakenly.
  2. Step 2: Verify other options

    Mock servers must be enabled; stub server down would not cause stub responses; Postman supports dynamic mocks.
  3. Final Answer:

    The mock server URL is incorrectly set to the stub server URL in the tests. -> Option C
  4. Quick Check:

    Wrong URL causes stub responses [OK]
Hint: Check URLs to avoid mixing mock and stub servers [OK]
Common Mistakes:
  • Assuming mock server is disabled by default
  • Believing stub server downtime causes stub responses
  • Thinking Postman lacks dynamic mock support
  • Ignoring URL configuration in tests
5. You want to test an API that returns different user roles based on request headers. Which approach best uses Postman mocks and stubs together to ensure reliable and flexible testing?
hard
A. Use neither mocks nor stubs; test only against the live API.
B. Use only stubs with fixed responses for all role variations to simplify tests.
C. Use only mocks with dynamic responses and avoid stubs to prevent confusion.
D. Use a mock server to simulate dynamic role responses and a stub with fixed responses for basic role tests.

Solution

  1. Step 1: Identify need for dynamic and fixed responses

    Testing different user roles requires dynamic responses for flexibility and fixed responses for stable baseline tests.
  2. Step 2: Combine mocks and stubs effectively

    Mocks simulate dynamic role-based responses; stubs provide fixed responses for simple, repeatable tests.
  3. Final Answer:

    Use a mock server to simulate dynamic role responses and a stub with fixed responses for basic role tests. -> Option D
  4. Quick Check:

    Mocks dynamic + stubs fixed = best combo [OK]
Hint: Combine mocks for dynamic and stubs for fixed tests [OK]
Common Mistakes:
  • Using only stubs loses dynamic testing benefits
  • Using only mocks may complicate simple tests
  • Ignoring mocks and stubs reduces test reliability
  • Testing only live API risks instability