Persisting a Fail as a test result with SetNextRequest

I’m setting up a automated test that runs through multiple requests.
If a test doesn’t get any data returned, then I want to set a next request.
This works. But i want to get notified that the test is failed in the Test Result.

Can someone help me with the code?

The response I could get and where I want to manualy set a new request:

    "response": {
        "ResultData": [
                "valk": []

Test i made:

let json = pm.response.json();
if (json.response.ResultData[0].valk.length === 0) {"Test is failed and next request is set");
} else {
    pm.collectionVariables.set("valk1RowKey", json.response.ResultData[0].valk[0].RowKey);
  • Here I want to give a Fail with a comment so i can see it in my Test Results.
  • I made up the ‘’ as an example. I don’t know the right syntax for it or if it even exists.

My recommendation would be to write a proper test checking the array, and have the IF statement outside of this.

let json = pm.response.json();

pm.test("Expect valk to be an array that is not empty", () => {
if (json.response.ResultData[0].valk.length === 0) {

If you really want to write something directly to the test results tab, the following should work.

pm.test("my test name", () => { throw new Error("error message") });


This workes like a charm. Thanks for your help and recommendations.
This is helping me learn to write better tests :).

1 Like