0
0
Postmantesting~10 mins

Why automated assertions validate responses in Postman - Test Execution Impact

Choose your learning style9 modes available
Test Overview

This test sends a request to an API endpoint and uses automated assertions to check if the response status is 200 and the response body contains the expected data. It verifies that the API works correctly and returns the right information.

Test Code - Postman
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
1Test starts and sends GET request to API endpointPostman sends request to https://api.example.com/user/123-PASS
2Receives response with status 200 and JSON bodyResponse status: 200 OK, Body: {"id":123,"name":"John Doe"}-PASS
3Runs assertion to check status code is 200Response status is 200pm.response.to.have.status(200)PASS
4Runs assertion to check response body contains name 'John Doe'Response JSON parsed, name field foundpm.expect(jsonData.name).to.eql("John Doe")PASS
Failure Scenario
Failing Condition: Response status is not 200 or name field is missing or different
Execution Trace Quiz - 3 Questions
Test your understanding
What does the first assertion check in this test?
AThat the response status code is 200
BThat the response body contains the word 'user'
CThat the request was sent successfully
DThat the response time is less than 1 second
Key Result
Automated assertions help quickly and reliably check if API responses meet expected conditions, saving time and reducing human error in testing.