If you want use Tests inside Postman, you must always write assertions like this:
pm.test('Response should have JSON Body', function () {
pm.response.to.have.jsonBody();
});
// or
tests["Response Data is Valid"] = tv4.validate(pm.response.json(), schema);
It will be better if we can use Reusable functions
inside Postman. It's more flexible...
To have Assertions inside your Collection, you need to do next steps:
- Save content of
pm_asserts.min.js
script as a global variable - In the Postman
Test scripts
- evalpostman_asserts
global variable - Call Asserts functions by functions' name
To set up Assertions - just download Collection and make API call with it. This Request will get Script content and set up Global variable into Postman Environment.
Into Tests
window call Assertions after eval()
Postman Globals variable, which contains Script body.
eval(globals.postman_asserts);
const schema = {
"type": "object",
"required": ['args', 'headers']
};
isJsonResponse();
isResponseStatus(200);
validateJsonSchema(schema);
This project is open source software licensed under the GNU General Public License version 3.