0
0
Postmantesting~10 mins

Why response validation confirms correctness in Postman - Test Execution Impact

Choose your learning style9 modes available
Test Overview

This test sends a request to an API endpoint and checks the response status and body content. It verifies that the API returns the expected data, confirming the correctness of the response.

Test Code - Postman Tests
Postman
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

pm.test("Response has expected user name", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData.name).to.eql("John Doe");
});
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Send GET request to API endpoint /users/123Postman sends HTTP GET request to the server-PASS
2Receive HTTP response from serverResponse received with status code 200 and JSON body-PASS
3Check if response status code is 200Response status code is 200 OKpm.response.to.have.status(200)PASS
4Parse response JSON and check if 'name' field equals 'John Doe'Response JSON contains {"name": "John Doe", ...}pm.expect(jsonData.name).to.eql("John Doe")PASS
Failure Scenario
Failing Condition: Response status code is not 200 or 'name' field does not match 'John Doe'
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test check first after receiving the response?
AIf the status code is 200
BIf the response time is less than 1 second
CIf the response body is empty
DIf the server is reachable
Key Result
Validating both the response status code and key response data ensures the API behaves correctly and returns expected results, which confirms the correctness of the response.