0
0
Postmantesting~10 mins

Tests tab and pm.test() in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if the API response status is 200 and if the response body contains a specific key. It uses pm.test() in Postman's Tests tab to verify these conditions.

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

pm.test("Response has userId", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData).to.have.property('userId');
});
Execution Trace - 3 Steps
StepActionSystem StateAssertionResult
1Test starts in Postman Tests tabPostman is ready to run the test scripts after receiving the API response-PASS
2pm.test("Status code is 200") runs and checks response statusAPI response received with HTTP status code 200Verify response status code equals 200PASS
3pm.test("Response has userId") runs and checks response bodyResponse body parsed as JSON, contains key 'userId'Verify response JSON has property 'userId'PASS
Failure Scenario
Failing Condition: Response status is not 200 or response JSON does not have 'userId' property
Execution Trace Quiz - 3 Questions
Test your understanding
What does the first pm.test() check in this test?
AThat the response time is less than 200ms
BThat the response status code is 200
CThat the response body contains 'userId'
DThat the response headers include Content-Type
Key Result
Use pm.test() in Postman's Tests tab to write clear, separate checks for response status and body content, making it easy to identify which part fails.