Is there a way of including a predefined set of tests into a collection
As a simple example, let’s say a number of tests include the following json that we want to run tests against
{
"success": true,
"message": "Some sort off response",
"error": null
//more json
}
we then write the following tests
pm.test("my_test json validation", function () {
var jsonData = pm.response.json();
pm.expect(jsonData).to.be.an("object");
pm.expect(jsonData.success).to.be.true;
pm.expect(jsonData.message).to.be.a("string");
pm.expect(jsonData.user.hasOwnProperty("error")).to.be.true;
if (!jsonData.success) {
pm.expect(jsonData.error).to.be.a("string");
}
What I would prefer is something like this
pm.test("my_test json validation", function () {
@include success_tests
pm.test("my_test2 json validation", function () {
@include success_tests
...
where sucess_tests would be an extension of a collection variables to include
var jsonData = pm.response.json();
pm.expect(jsonData).to.be.an("object");
pm.expect(jsonData.success).to.be.true;
pm.expect(jsonData.message).to.be.a("string");
pm.expect(jsonData.user.hasOwnProperty("error")).to.be.true;
if (!jsonData.success) {
pm.expect(jsonData.error).to.be.a("string");
}