postman断言

 断言一般都在Tests模块进行操作

 

Postman自带的Tests函数,常用的断言代码有如下几种:

Status code is 200 (状态码为200)

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

 

Code name contains a string (代码名称包含一个字符串)

pm.test("Body matches string", function () {
    pm.expect(pm.response.text()).to.include
        ("resultcode\":\"200");
});

 

Set a global varable (设置一个全局变量)

pm.globals.set("access", token);

 

Response body:JSON value check (检查JOSN的值)

pm.test("Your test name", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.value).to.eql(100);
});

 

 

作者:小汤o

posted @ 2020-06-28 08:28  小汤o  阅读(81)  评论(0编辑  收藏  举报