希望将收集级别responseCode.code test设置为只接受两个状态代码-200和204。
在收藏层面,我写了这样一篇:
if (responseCode.code === 204) {
console.log("204");
} else {
if (responseCode.code !== 200){
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
let responseJSON = JSON.parse(responseBody);
console.log(responseJSON);
return;
}
}
它正确地检查状态,但如果错误则作为代码错误抛出(例如返回500服务器错误),而不是预期的失败。因此,在TeamCity CI中,它不会被突出显示为失败的测试
是否有人在你的收藏中使用了类似的东西:
pm.response.to.have.status(200);
responseCode.code