Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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
✗ 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?
Apm.response.text()
Bpm.response.json()
Cpm.response.body()
Dpm.response.parse()
✗ 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?
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')
✗ 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?
AThe test is marked as failed
BThe API call is retried automatically
CThe response body is ignored
DThe test is marked as passed
✗ 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?
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
✗ 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.
Practice
(1/5)
1. What does pm.response.json() do in Postman tests?
easy
A. It parses the response body as a JSON object.
B. It sends a new request to the server.
C. It clears the response body.
D. It validates the response status code.
Solution
Step 1: Understand the purpose of pm.response.json()
This function reads the response body and converts it into a JSON object for easy access.
Step 2: Compare with other options
Sending requests, clearing body, or validating status are different functions, not pm.response.json().
Final Answer:
It parses the response body as a JSON object. -> Option A
Quick Check:
Parsing response body = A [OK]
Hint: Remember: json() reads response body as JSON [OK]
Common Mistakes:
Confusing json() with sending requests
Thinking json() clears data
Mixing response body parsing with status code checks
2. Which of the following is the correct syntax to assert that the response JSON has a key status with value success in Postman?
easy
A. pm.expect(response.status).to.equal('success');
B. pm.response.json().status == 'success';
C. pm.expect(pm.response.json().status).to.eql('success');
D. pm.assert(pm.response.status == 'success');
Solution
Step 1: Identify correct assertion syntax in Postman
Postman uses pm.expect() with Chai assertion style, so pm.expect(pm.response.json().status).to.eql('success'); is correct.
Step 2: Check other options for errors
pm.response.json().status == 'success'; lacks assertion, C uses wrong object, D uses incorrect method.
Final Answer:
pm.expect(pm.response.json().status).to.eql('success'); -> Option C
Quick Check:
Use pm.expect() with to.eql() for value check [OK]
Hint: Use pm.expect() with to.eql() for JSON value checks [OK]
Common Mistakes:
Using == instead of pm.expect() for assertions
Referencing response.status instead of response.json().status
Using pm.assert() which is not a Postman function
3. Given this response body:
{"user":{"id":5,"name":"Alice"}}
What will this test output?
const jsonData = pm.response.json();
pm.test("User ID is 5", () => {
pm.expect(jsonData.user.id).to.equal(5);
});
medium
A. Test passes because user.id equals 5.
B. Test fails because user.id is not 5.
C. Test throws an error due to syntax.
D. Test is skipped because no assertion is made.
Solution
Step 1: Parse the response JSON
The response has user.id = 5, so jsonData.user.id is 5.
Step 2: Evaluate the assertion
The test asserts jsonData.user.id equals 5, which is true, so the test passes.
Final Answer:
Test passes because user.id equals 5. -> Option A
Quick Check:
Value matches assertion = Pass [OK]
Hint: Match JSON path value with expected to pass test [OK]
Common Mistakes:
Misreading JSON structure
Assuming test fails without checking value
Confusing syntax errors with assertion failures
4. Identify the error in this Postman test code:
const data = pm.response.json();
pm.test("Check user name", () => {
pm.expect(data.user.name).to.equal('Bob')
});
medium
A. Missing semicolon after assertion line.
B. No error; the test code is correct.
C. Incorrect function name; should be pm.test, not pm.tests.
D. Missing parentheses after pm.expect.
Solution
Step 1: Review syntax of Postman test code
The code uses pm.test correctly, with proper arrow function and assertion syntax.
Step 2: Check for syntax errors
Semicolons are optional in JavaScript; parentheses and function names are correct.
Final Answer:
No error; the test code is correct. -> Option B
Quick Check:
Correct syntax means no error [OK]
Hint: Check function names and parentheses carefully [OK]
Common Mistakes:
Confusing pm.test with pm.tests
Thinking semicolons are mandatory
Missing parentheses in pm.expect
5. You want to assert that the response JSON array items contains an object with id equal to 10. Which test code correctly checks this in Postman?
hard
A. pm.expect(pm.response.json().items.id).to.equal(10);
B. const items = pm.response.json().items;
pm.expect(items.find(id => id === 10)).to.exist;
C. pm.expect(pm.response.json().items.includes({id:10})).to.be.true;
D. const items = pm.response.json().items;
pm.expect(items.some(item => item.id === 10)).to.be.true;
Solution
Step 1: Understand the response structure
items is an array of objects; we want to check if any object has id 10.
Step 2: Evaluate each option
const items = pm.response.json().items;
pm.expect(items.some(item => item.id === 10)).to.be.true; uses some() to check if any item has id === 10, which is correct. pm.expect(pm.response.json().items.id).to.equal(10); wrongly accesses items.id (invalid). pm.expect(pm.response.json().items.includes({id:10})).to.be.true; tries to use includes() with an object, which won't work. const items = pm.response.json().items;
pm.expect(items.find(id => id === 10)).to.exist; uses find() but the callback is incorrect (should check item.id).