在邮递员中,如何根据另一个测试是否通过来运行新测试?

问题描述

我有两个测试A和B。我希望B仅在A通过的情况下运行。我如何在邮递员中做到这一点?

pm.test("Status code is 200",function() {
    pm.response.to.have.status(200);
});
pm.test("Check if fruits found with this search criteria",function() {
    pm.expect(responseData.Message).to.not.eql("No fruits found with this search criteria");
});

仅当这两个测试用例通过时,我才想运行第三个测试。我怎样才能做到这一点? 预先感谢。

解决方法

您可以简单地嵌套测试:

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

    pm.test("Check if fruits found with this search criteria",function() {
        pm.expect(responseData.Message).to.not.eql("No fruits found with this search criteria");

        pm.test("Third test",function() {
            //pm.expect()...
        });
    });
});