postman中Test断言介绍

一,常用断言:

前4种最常用

1)Status code:Code is 200 检查返回的状态码是否为200

2)Response body:Contains string 检查响应中包括指定字符串

// pm.test("Body matches string", function () {
//     pm.expect(pm.response.text()).to.include("string_you_want_to_search");
// });

pm.test("Body matches string", function () {
    pm.expect(pm.response.text()).to.include("email");
});

3)Response body:Json value check 检查响应中其中json的值

// pm.test("Your test name", function () {
//     var jsonData = pm.response.json();
//     pm.expect(jsonData.value).to.eql(100);
// });
pm.test("Your test name", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.list[0]).to.eql("第一个数");
});

4)Response body:is equal to a string 检查响应等于一个字符串

response_body_string处填写的内容要和接口返回的内容完全一致才可以匹配成功

// pm.test("Body is correct", function () {
//     pm.response.to.have.body("response_body_string");
// });

5)Response headers:Content-Type…检查是否包含响应头Content-Type


pm.test("Content-Type is present", function () {
    pm.response.to.have.header("Content-Type");
});

6)Response time is less than 200ms:检查请求耗时小于200ms

pm.test("Response time is less than 200ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(200);
});

7)Status code :Successfull POST request :判断post请求的状态码,是不是在201和202这两个之中

pm.test("Successful POST request", function () {
    pm.expect(pm.response.code).to.be.oneOf([201, 202]);
});

二,使用参数

global全局参数

断言使用参数

Postman内置动态参数和自定义的动态参数以及断言方式

   {{$timestamp}}  生成当前时间的时间戳。

   {{$randomInt}}  生成0-1000之间的随机数

   {{$guid}}           生成速记GUID字符串
  • 23
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值