0
0
Postmantesting~10 mins

Defining mock responses in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks that a Postman mock server returns the correct predefined response when a specific API request is made. It verifies the mock response status and body content.

Test Code - Postman Test Scripts
Postman
pm.test('Mock response returns status 200', () => {
    pm.response.to.have.status(200);
});

pm.test('Mock response body contains expected message', () => {
    const jsonData = pm.response.json();
    pm.expect(jsonData.message).to.eql('Hello from mock server');
});
Execution Trace - 3 Steps
StepActionSystem StateAssertionResult
1Send GET request to Postman mock server endpointPostman sends request to mock server URL configured with predefined response-PASS
2Receive HTTP response from mock serverResponse status 200 and body {"message": "Hello from mock server"} receivedCheck response status is 200PASS
3Parse response JSON and verify 'message' fieldResponse JSON parsed successfullyVerify response body message equals 'Hello from mock server'PASS
Failure Scenario
Failing Condition: Mock server returns a different status code or response body than expected
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify first after sending the request?
AResponse headers contain Content-Type
BResponse time is less than 1 second
CResponse status code is 200
DResponse body contains a list
Key Result
Always verify that your mock server is configured with the correct response for the exact request URL to ensure reliable and predictable test results.