0
0
Postmantesting~20 mins

Mock vs stub comparison in Postman - Practice Questions

Choose your learning style9 modes available
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.