一、什么是断言?
断言是验证实际结果跟预期结果是否一致。一致则用例验证通过;不一致,则用例验证失败。
二、postman工具如何使用断言?
在test里面写脚本来实现断言。
快速方法,详见SNIPPETS列表:
断言常见的方法:
1、验证响应的数据是否包含某一字符串
pm.test("Body matches string", function () {
pm.expect(pm.response.text()).to.include("string_you_want_to_search");
});
2、验证响应code
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
查看断言结果:
3、验证返回json值
pm.test("Your test name", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.content.userInfo.userName).to.eql("郭英谱");
});