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?
✗ Incorrect
Response body assertions check the actual data returned by the API to ensure it matches what is expected.
Which Postman method is used to parse the response body as JSON?
✗ Incorrect
pm.response.json() parses the response body as JSON so you can access its properties.
How do you check if a response body contains a property named 'status' in Postman?
✗ Incorrect
The correct way is to check if the object has the property using to.have.property.
What happens if a response body assertion fails in Postman?
✗ Incorrect
If an assertion fails, Postman marks the test as failed to indicate a problem.
Which of these is a valid assertion to check if a response body array is not empty?
✗ Incorrect
Checking that the length is above 0 confirms the array has at least one item.
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.