pm.test('Check if employee filled their skills', function() {
jsonData.forEach(function(item) {
expect(item.MainEmployeeSkills).to.be.not.empty;
if (item.MainEmployeeSkills.length < 1) {
console.log(item.fullName + " doesn't have skills");
}
})
})
在expect之后,代码是无法访问的。但我想知道测试失败并记录结果。求求你,帮帮忙
发布于 2021-01-17 15:18:43
var jsonData = [2, 2, 3, 2, 2]
jsonData.forEach(function (a) {
pm.test("Your test name", function () {
if (item.MainEmployeeSkills.length < 1) {
console.log(item.fullName + " doesn't have skills");
}
pm.expect(a).to.eql(2);
});
})
您应该在pm.expect之前打印它,因为它抛出了一个异常,并且不会执行nexyt行。
此外,在pm.text中使用for循环也没有意义,因为除了它本身之外,第一个循环都存在(除非这是您想要的)。
如果您正在寻找打印描述性断言消息的方法,请不要这样做。请改用:
pm.test('Check if employee filled their skills', function() {
jsonData.forEach(function(item) {
pm.expect(item.MainEmployeeSkills,item.fullName + " doesn't have skills").to.be.not.empty;
})
})
https://stackoverflow.com/questions/65762210
复制相似问题