2

是否可以停止在预请求脚本中运行的测试但不能停止整个测试集合的运行?

我看过各种帖子提到这些方式:

  • postman.setNextRequest(null);
  • throw new Error("Error");

这些将阻止测试完成,但似乎也停止了我不想要的整个测试集合运行。

更新

预请求脚本:

var test = 'Wait for create transaction request to complete';

var numRetriesRemaining = postman.getEnvironmentVariable("numRetriesUntilCompletionExpected");

if (numRetriesRemaining == -1) {
    // stop the request from being sent and stop the "Tests" part from running 
    // but also don't stop other tests in the collection
}
4

1 回答 1

0

如果我误解了你,那么我会更新这个答案。


在测试脚本中写一个简单return的可以停止测试脚本的进一步执行。

您可以在预请求脚本中执行以下操作:

pm.test('This test should run', function () {});

pm.test('This test should also run', function () {});

return;

pm.test('This test should not run', function () {});

您也可以在测试中添加一个 return 来停止测试的执行。例如:

pm.test('This test should execute only one case and not the last one', function () {
    pm.expect(1).to.equal(1); // This will execute

    return;

    pm.expect(2).to.equal(1); // This will not execute
});
于 2019-04-02T12:31:39.833 回答