0
0
Postmantesting~20 mins

Reusable test scripts in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Reusable Test Scripts Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Postman test script?

Consider this Postman test script that uses a reusable function to check response status:

function checkStatus(expected) {
    pm.test(`Status is ${expected}`, function () {
        pm.response.to.have.status(expected);
    });
}

checkStatus(200);

What will be the test result if the response status is 404?

Postman
function checkStatus(expected) {
    pm.test(`Status is ${expected}`, function () {
        pm.response.to.have.status(expected);
    });
}

checkStatus(200);
ATest fails with syntax error in function definition
BTest fails with message 'Status is 200' because actual status is 404
CTest passes because function runs without error
DTest passes because 404 is treated as 200 internally
Attempts:
2 left
💡 Hint

Think about what happens when the expected status does not match the actual response status.

assertion
intermediate
2:00remaining
Which assertion correctly reuses a variable for checking JSON response property?

You want to reuse the variable userId in multiple assertions in Postman tests. Which option correctly asserts that the response JSON has userId equal to 5?

Postman
const userId = 5;
pm.test('User ID is correct', () => {
    // assertion here
});
Apm.expect(pm.response.json().userId).to.eql('userId');
Bpm.expect(pm.response.json().userId).to.eql(5);
Cpm.expect(pm.response.json().userId).to.eql(userId.toString());
Dpm.expect(pm.response.json().userId).to.eql(userId);
Attempts:
2 left
💡 Hint

Remember to use the variable name without quotes to refer to its value.

🔧 Debug
advanced
2:00remaining
Why does this reusable test script fail to run in Postman?

Look at this reusable test script snippet intended to check response time:

function checkResponseTime(maxTime) {
    pm.test('Response time is acceptable', () => {
        pm.expect(pm.response.responseTime).to.be.below(maxTime);
    });
}

checkResponseTime(200);

When running, the test always passes even if response time is above 200ms. Why?

Postman
function checkResponseTime(maxTime) {
    pm.test('Response time is acceptable', () => {
        pm.expect(pm.response.responseTime).to.be.below(maxTime);
    });
}

checkResponseTime(200);
Apm.response.responseTime is in milliseconds, but the test expects seconds
BThe function is not called properly, so test is skipped
Cpm.response.responseTime is in seconds, but maxTime is in milliseconds
Dpm.response.responseTime is undefined, so assertion always passes
Attempts:
2 left
💡 Hint

Check the units of pm.response.responseTime and the argument maxTime.

framework
advanced
2:00remaining
How to best organize reusable test scripts in Postman collections?

You want to reuse test scripts across multiple requests in a Postman collection. Which approach is best practice?

AWrite reusable functions in the collection <code>Tests</code> tab and call them in each request test script
BCopy and paste the same test code into each request's <code>Tests</code> tab
CUse environment variables to store test scripts as strings and eval them in each request
DWrite reusable test scripts only in the pre-request scripts
Attempts:
2 left
💡 Hint

Think about maintainability and avoiding duplication.

🧠 Conceptual
expert
2:00remaining
What is the main advantage of using reusable test scripts in Postman?

Choose the best explanation for why reusable test scripts improve API testing in Postman.

AThey guarantee 100% test coverage without writing additional tests
BThey allow tests to run faster by caching previous results automatically
CThey reduce code duplication, making tests easier to maintain and update consistently
DThey enable running tests without any network connection
Attempts:
2 left
💡 Hint

Think about maintainability and efficiency in test writing.