0
0
Postmantesting~5 mins

Response body assertions in Postman - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a response body assertion in API testing?
It is a check to confirm that the data returned by an API matches what we expect. This helps ensure the API works correctly.
Click to reveal answer
beginner
How do you check if a response body contains a specific key-value pair in Postman?
Use JavaScript in the Tests tab, for example: <br><code>pm.test('Check key value', () => {<br>  const jsonData = pm.response.json();<br>  pm.expect(jsonData.key).to.eql('value');<br>});</code>
Click to reveal answer
beginner
Why is it important to assert the response body in API tests?
Because it verifies the API returns the correct data, not just a successful status code. This prevents bugs and ensures the app works as expected.
Click to reveal answer
beginner
What does this Postman test do? <br><code>pm.test('Response has userId', () => {<br>  const jsonData = pm.response.json();<br>  pm.expect(jsonData).to.have.property('userId');<br>});</code>
It checks that the response body includes a property named 'userId'. If 'userId' is missing, the test will fail.
Click to reveal answer
intermediate
How can you assert that a response body array has at least one item in Postman?
Use this test:<br><code>pm.test('Array is not empty', () => {<br>  const jsonData = pm.response.json();<br>  pm.expect(jsonData.length).to.be.above(0);<br>});</code>
Click to reveal answer
What does a response body assertion verify in API testing?
AThe data returned by the API matches expected values
BThe API server is running
CThe API response time is fast
DThe API URL is correct
Which Postman method is used to parse the response body as JSON?
Apm.response.text()
Bpm.response.json()
Cpm.response.body()
Dpm.response.parse()
How do you check if a response body contains a property named 'status' in Postman?
Apm.expect(jsonData.status).to.be.undefined
Bpm.expect(jsonData.status).to.be.null
Cpm.expect(jsonData).to.include('status')
Dpm.expect(jsonData).to.have.property('status')
What happens if a response body assertion fails in Postman?
AThe test is marked as failed
BThe API call is retried automatically
CThe response body is ignored
DThe test is marked as passed
Which of these is a valid assertion to check if a response body array is not empty?
Apm.expect(jsonData.length).to.equal(0)
Bpm.expect(jsonData).to.be.empty
Cpm.expect(jsonData.length).to.be.above(0)
Dpm.expect(jsonData).to.be.null
Explain how to write a response body assertion in Postman to verify a specific value.
Think about how you get the data and then check it.
You got /4 concepts.
    Why is it important to include response body assertions in your API tests?
    Consider what could go wrong if you only check status codes.
    You got /4 concepts.