Challenge - 5 Problems
Postman Tests Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the test result of this Postman test script?
Consider this Postman test script in the Tests tab:
Assuming the response status is 200 and response time is 450ms, what will be the test execution result?
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Response time is less than 500ms", function () {
pm.expect(pm.response.responseTime).to.be.below(500);
});Assuming the response status is 200 and response time is 450ms, what will be the test execution result?
Postman
pm.test("Status code is 200", function () { pm.response.to.have.status(200); }); pm.test("Response time is less than 500ms", function () { pm.expect(pm.response.responseTime).to.be.below(500); });
Attempts:
2 left
💡 Hint
Check the status code and response time conditions carefully.
✗ Incorrect
The first test checks if the status code is exactly 200, which it is. The second test checks if the response time is below 500ms, which 450ms satisfies. So both tests pass.
❓ assertion
intermediate2:00remaining
Which pm.test assertion correctly checks if JSON response has a key 'userId'?
You want to write a test in Postman to verify that the JSON response body contains the key 'userId'. Which pm.test assertion below will correctly do this?
Attempts:
2 left
💡 Hint
Check which method correctly tests for a property in an object.
✗ Incorrect
Option B uses the correct Chai assertion to check if the JSON object has the property 'userId'. Option B uses 'to.exist' on a value which may fail if userId is falsy. Option B and D use invalid methods for objects.
🔧 Debug
advanced2:00remaining
Why does this pm.test fail with a TypeError?
Look at this Postman test code:
What causes the TypeError during test execution?
pm.test("Check user name", function() {
let jsonData = pm.response.json;
pm.expect(jsonData.name).to.eql("Alice");
});What causes the TypeError during test execution?
Postman
pm.test("Check user name", function() { let jsonData = pm.response.json; pm.expect(jsonData.name).to.eql("Alice"); });
Attempts:
2 left
💡 Hint
Check how to correctly get JSON data from the response.
✗ Incorrect
pm.response.json is a function that returns the parsed JSON body. Without parentheses, jsonData is assigned the function itself, causing a TypeError when accessing .name.
🧠 Conceptual
advanced2:00remaining
What is the purpose of pm.test() in Postman?
Select the best description of what pm.test() does in Postman test scripts.
Attempts:
2 left
💡 Hint
Think about how tests are structured in Postman.
✗ Incorrect
pm.test() wraps assertions inside a named test case. It does not send requests, log output, or retry requests.
❓ framework
expert2:00remaining
Which option correctly waits for a response before running pm.test assertions in Postman?
You want to write a test script that runs assertions only after the response is fully received. Which code snippet correctly ensures this in Postman?
Attempts:
2 left
💡 Hint
Check which method uses a callback after the request completes.
✗ Incorrect
Option A uses pm.sendRequest with a callback that runs tests after the response arrives. Option A runs tests immediately on the current response. Options C and D use non-existent event or method.