postman使用心得(二):postman接口测试断言

在使用postman做接口测试的时候,可以在tests中对该接口进行断言设置

json字符串解析断言

上面的图为使用postman断言方法之一,使json解析key的值进行校验

tests["Your test name"] = jsonData.value === 100;

其中 Your test name 为断言名,jsonData.value表示为对json进行解析,=== 100 表示为key的value值

{
  "ok": true,
  "data": {
    "user": {
      "user_no": "888",
      "type": "1",
      "user_name": "W HE",
      "fullname": "W HE",
      "nickname": "",
      "login_name": "1258@qq.com",
      "headimg": "",
      "is_payed": true,
      "is_certified": false
    },
    "redirect_url": "/team/search"
  }
}

jsonData["data"]["user"]["user_name"] === "W HE"

附:

常用的postman断言 解释 对应脚本
Response body:Contains string response包含字符串 tests["Body matches string"] = responseBody.has("string_you_want_to_search");
Response body:Is equal to a string response body等于指定字符串 tests["Body is correct"] = responseBody === "response_body_string";
response body:JSON value check json解析key的值进行校验 tests["Your test name"] = jsonData.value === 100;
status code:Code is 200 判断状态码 tests["Status code is 200"] = responseCode.code === 200;
status code:code name has string 检查code name 是否包含内容 tests["Status code name has string"] = responseCode.name.has("Created");
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 每一个季节都值得被好好对待,什么是你们夏天一定会做的事呢? 关于夏天的记忆,还是小时候最有感觉。 那时候没有高楼林...
    a62f642158e4阅读 366评论 0 0
  • 一道选择题 首先我们先来看一道选择题。 假设有两个按钮,如果你按下第一个,直接给你100万元;如果按下第二个,则有...
    严过留痕295阅读 679评论 0 0
  • 柔条柳树绒花, 街道和风车马, 丽阳正南高桂, 归乡人到楼下。
    张玉民阅读 396评论 0 0