Test result (as boolean)

Let’s say I have a test, eg

pm.test("Status code is 301", function () {
    pm.response.to.have.status(301);
});

and I want the following actions to depend on wether the test passed or failed.

How to get the test result (as boolean)?

Thanks,
Christian

Hey @chrissbaumann,
I tried the following snippet and it prints “Test failed”

 pm.test("Check response code", function () {
        try{
            pm.expect(responseStatus).to.equal(200)
            console.log("Test passed")  
        }catch(err){
            console.log("Test failed")
            //Add your action here
        }
    });

I’m curious however to understand more about the use case. Could you elaborate on what kinds of actions you would trigger based on the results of the test?

1 Like

Thank you!

No specific use case for me.
Saw couple of questions on StackOverflow, where this would have been useful.
Mostly asking to do things, I would not advise for from a testing perspective…

1 Like