3

这是我在邮递员中的测试用例

pm.test("verify the JSON object keys for machines - ", function() {
    if (Object.keys(data).length === 0) {
        pm.expect(Object.keys(data).length).to.eq(0);
    }
}

现在如果这个测试的状态是PASS然后我不想执行下一个测试用例但是如果状态是FAIL那么下一个测试用例应该被执行下一个测试用例是 -

pm.test("verify the JSON object keys for machines- ", function() {
        pm.expect(data[1]).to.have.property('timeStamp');
    }
4

2 回答 2

3

也许这可以通过以编程方式跳过测试来实现。这是语法

(condition ? skip : run)('name of your test', () => {

});

取一个变量,如果第一次测试的结果通过则更新它

var skipTest = false;

pm.test("verify the JSON object keys for machines - ", function() {
    if (Object.keys(data).length === 0) {
        pm.expect(Object.keys(data).length).to.eq(0);
        skipTest = true // if the testcase is failed, this won't be updated
    }
}

(skipTest ? pm.test.skip : pm.test)("verify timeStamp keys for machines-", () => {
     pm.expect(data[1]).to.have.property('timeStamp');
});

结果跳过

在此处输入图像描述

结果不跳过

在此处输入图像描述

于 2019-11-27T06:51:30.377 回答
1

从逻辑上讲,您需要“或”功能,但邮递员中没有这样的功能。我的建议是得到真/假结果,并与邮递员一起检查。

pm.test("verify the JSON object keys for machines - ", function() {
    const result = 
        Object.keys(data).length === 0 || // true if there are no properties in the data object
        'timeStamp' in data; // or true if there is timeStamp property in the data object
    
    pm.expect(lengthEqualZero || hasPropertyTimeStamp).to.be.true;
}

于 2019-11-24T10:13:46.353 回答