Is there a way to exit a set of tests for a given request early. So in the example below, cut down and simplified, if I don’t get a Person object returned then I’d like to exit at that point. I know I can use a “throw new Error()” but if I do then I can’t see the results of the earlier tests.
Wherever you want to ‘Exit’ you can just use the ‘return’ command.
Mind you, if you use ‘return’ inside a function, it just returns out of the function.
I’ve used it at the script level with no problems.
There might be a better way. If so, wait on for further replies on this thread… I’ll be curious as well.
In addition to the above response, there’s also another way to directly control the skipping of the complete tests using some control boolean.
You can either use an environment variable or you can perform the computation in the test script whether you want to set a test (or a set of tests) and use that.
For eg:
let skipTest = pm.environment.get('skipTest');
(skipTest ? pm.test.skip : pm.test)("Check status code", () => {
pm.expect(pm.response.code).to.equal(200);
});
(skipTest ? pm.test.skip : pm.test)("Check status code is not 404", () => {
pm.expect(pm.response.code).to.not.equal(404);
});
@singhsivcan, i’m starting withg testing API with script and often use is.a(“object”) or array and often my script breaks the run for exemple when i expect an array, in a next test or a bit late i’m assiging environment variable from the expected response like jsonData[0].myvalue but when the call is returning an error or an object (as managed error message {error:{message:“this is wrong”,code:1234}), the the assignment is generating an error TypeError: Cannot read property ‘0’ of undefined
What would you reocmmand to early avoid thse and be able to continue testing runs, setting the test to fail before getting to the actual/next tests?