0
0
Postmantesting~10 mins

Test utilities and helpers in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test uses Postman test utilities to check if the API response status is 200 and if the response body contains a specific key with the expected value.

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

pm.test("Response has userId with value 1", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData.userId).to.eql(1);
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsPostman app is open with the API request ready-PASS
2Send API requestRequest sent to the server, waiting for response-PASS
3Receive API responseResponse received with status 200 and JSON bodyCheck if response status is 200PASS
4Parse response JSONResponse body parsed into JSON objectVerify jsonData.userId equals 1PASS
5Test endsAll assertions passed, test completed successfully-PASS
Failure Scenario
Failing Condition: Response status is not 200 or userId value is not 1
Execution Trace Quiz - 3 Questions
Test your understanding
What does the first test in the Postman script verify?
AThe response status code is 200
BThe response body contains userId
CThe response time is less than 200ms
DThe request headers are correct
Key Result
Using Postman's built-in test utilities like pm.response.to.have.status and pm.expect helps write clear and reliable tests that verify API responses effectively.