断言:
通过代码自动判断实际返回结果与预期结果是否一致
断言一致为pass
断言不一致为fail
Postman断言:
写在tests中,通过javascript编写,断言结果会在testResult中
常用断言
1,断言响应状态码是否为200--------postman代码块名称:status code is 200
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
2,断言响应体JSON数据校验-------postman代码块名称:response body:JSON value cleck
pm.test("Your test name", function () {
#定义一个变量,接收json类型的response
var jsonData = pm.response.json();
#value是响应json数据的键,eql( )括号里是json数据键对应的值,字符串用“ ”引起来
pm.expect(jsonData.value).to.eql(100);
});
3,断言响应体是否包含字符串------postman代码块名称:response body:Contains string
pm.test("Body matches string", function () {
pm.expect(pm.response.text()).to.include("响应数据例的部分字符串");
});```
4,断言响应体是否等于指定字符串------postman代码块名称:response body:is equal to a string
pm.test("Body is correct", function () {
pm.response.to.have.body("响应数据的body");
});
5,断言响应头是否包含指定的头信息-----postman代码块名称:response headers :content_type header check
pm.test("Content-Type is present", function () {
pm.response.to.have.header("请求头参数");
});