0
0
Postmantesting~20 mins

Tests tab and pm.test() in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Postman Tests Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the test result of this Postman test script?
Consider this Postman test script in the Tests tab:
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);
});
ABoth tests pass
BFirst test fails, second test passes
CFirst test passes, second test fails
DBoth tests fail
Attempts:
2 left
💡 Hint
Check the status code and response time conditions carefully.
assertion
intermediate
2: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?
Apm.test("Response has userId", () => { pm.expect(pm.response.json().userId).to.exist; });
Bpm.test("Response has userId", () => { pm.expect(pm.response.json()).to.have.property('userId'); });
Cpm.test("Response has userId", () => { pm.expect(pm.response.json().has('userId')).to.be.true; });
Dpm.test("Response has userId", () => { pm.expect(pm.response.json().includes('userId')).to.be.true; });
Attempts:
2 left
💡 Hint
Check which method correctly tests for a property in an object.
🔧 Debug
advanced
2:00remaining
Why does this pm.test fail with a TypeError?
Look at this Postman test code:
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");
});
AThe test function is missing a return statement
Bpm.expect is not defined in the Tests tab
Cpm.response.json is a function and needs to be called as pm.response.json()
DThe property 'name' does not exist in the response
Attempts:
2 left
💡 Hint
Check how to correctly get JSON data from the response.
🧠 Conceptual
advanced
2:00remaining
What is the purpose of pm.test() in Postman?
Select the best description of what pm.test() does in Postman test scripts.
AIt sends the HTTP request to the server and waits for the response.
BIt automatically retries the request if the test fails.
CIt logs the response body to the Postman console for debugging.
DIt defines a test case with a name and a function containing assertions to validate the response.
Attempts:
2 left
💡 Hint
Think about how tests are structured in Postman.
framework
expert
2: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?
Apm.sendRequest(request, function (err, res) { pm.test("Status is 200", () => { pm.expect(res).to.have.property('code', 200); }); });
Bpm.test("Status is 200", () => { pm.expect(pm.response.code).to.equal(200); });
Cpm.response.on('complete', () => { pm.test("Status is 200", () => { pm.expect(pm.response.code).to.equal(200); }); });
Dpm.waitForResponse(() => { pm.test("Status is 200", () => { pm.expect(pm.response.code).to.equal(200); }); });
Attempts:
2 left
💡 Hint
Check which method uses a callback after the request completes.