Jmeter接口自动化测试 —— Jmeter断言之Json断言
json断言可以让我们很快的定位到响应数据中的某一字段,当然前提是响应数据是json格式的,所以如果响应数据为json格式的话,使用json断言还是相当方便的。
还是以之前的接口举例
Url: https://data.cma.cn/weatherGis/web/weather/weatherFcst/getCurrentCondition
HTTP Method: Post
Request:
staId: 54511
Response:
{"v01301":"54511","v13003":71,"v12001":24.3,"v13011":0.0,"v11292":229.0,"v11293":1.6,"v20003":5.0,"d_DATETIME":2019,"d_IYMDHM":1566792218000,"d_RECORD_ID":2.08712269E9}
- 添加一个Json断言
![](https://img.shuduke.com/static_img/cnblogs/80/gwbsxgsa_llef.jpg)
- 维护上想要判断的字段
![](https://img.shuduke.com/static_img/cnblogs/80/oitnrpya_jsjx.jpg)
- 查看结果
![](https://img.shuduke.com/static_img/cnblogs/80/qwllhnqy_s0mm.webp)
我们将期望的值故意改成错的545111看看会不会报错
![](https://img.shuduke.com/static_img/cnblogs/80/jorcfdqp_k8yw.webp)
正则表达式
![](https://img.shuduke.com/static_img/cnblogs/80/upobiucc_5s47.webp)
期望是空
![](https://img.shuduke.com/static_img/cnblogs/80/xrgjddqu_txox.webp)