Verify custom test utility function for response validation
Preconditions (2)
✅ Expected Result: The test results show that the status code is 200 and the response body contains a 'users' array
function checkStatus200() {
pm.test('Status code is 200', function () {
pm.response.to.have.status(200);
});
}
function checkUsersArray() {
pm.test('Response has users array', function () {
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property('users').that.is.an('array');
});
}
// Call utility functions
checkStatus200();
checkUsersArray();The checkStatus200 function creates a test to verify the response status code is 200 using pm.response.to.have.status(200). This confirms the request succeeded.
The checkUsersArray function parses the JSON response and asserts that it has a property users which is an array. This checks the expected data structure.
Both functions are called in the Tests tab to keep the test code organized and reusable. Using pm.test and pm.expect provides clear pass/fail results in Postman.
Extend the test utilities to check that each user object in the 'users' array has 'id' and 'name' properties
pm.test('Check status', () => { pm.expect(isSuccess({code: 200})).to.be.true; });?
function isSuccess(response) {
return response.code === 200;
}function isValid(response) {
return response.status = 200;
} What is the error and how to fix it?data array. Which helper function below correctly implements this check?Pass the test and this pattern moves unknown