Which statement best describes the difference between a mock and a stub in API testing using Postman?
Think about whether the tool checks if the API was called correctly or just returns data.
Stubs return fixed responses to API calls but do not check if the calls happened as expected. Mocks do both: they return responses and verify the calls.
Given this Postman mock server setup that returns a fixed JSON response, what will be the response body when a GET request is sent?
{
"message": "Hello from mock",
"status": 200
}The mock server returns the predefined response exactly as configured.
The mock server always returns the fixed JSON response set up in Postman, regardless of the request details.
Which Postman test script assertion correctly verifies that the stubbed API response contains a 'userId' field with value 5?
pm.test("Check userId is 5", () => {
// assertion here
});Remember to parse JSON and use the correct assertion method in Postman.
pm.response.json() parses the response body as JSON. The method to check equality in Postman is 'to.eql()'.
What error will this Postman test script produce when run against a mock server response?
pm.test("Response has status 200", () => { pm.expect(pm.response.status).to.equal(200); });
Check how to access the response status code in Postman scripts.
In Postman, pm.response.status returns the status text (e.g., 'OK'), not the numeric code. The correct property is pm.response.code for status code.
Which approach best uses both mocks and stubs in Postman to test an API that depends on an external service?
Think about separating response simulation and call verification roles.
Stubs provide fixed responses to simulate external services. Mocks add verification to ensure the API calls happen as expected. Combining both improves test reliability.