断言
将测试断言数据写进到Test模块当中, 每次发送API请求的时候会自动进行断言检查数据。
常见的断言方法如下:
判断状态码:pm.response.to.have.status()
判断返回体: const responseJson = pm.response.json();pm.expect(responseJson.code).to.eql(0);
判断返回头:pm.response.headers.get()
拿气象局获取添加接口举例说明
url中填写:http://weather.cma.cn/api/climate?stationid=54511
在test模块添加下列代码
//判断状态码
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
//如果返回格式为JSON, 判断返回内容
pm.test("The response has all properties", () => {
//parse the response JSON and test three propertie