json断言主要用于请求返回的值为json格式,可以提取json中的值与预期结果进行比对

1、在请求下添加json断言

JMeter元件(六)-断言-6.2JSON断言_JMeter学习

2、界面如图

JMeter元件(六)-断言-6.2JSON断言_JMeter教程_02

请求的响应值如下,现在需要断言orderSn的值为5010020190702081850082

{"code":"0","msg":"操作成功","data":{"totalSize":1,"totalPage":1,"pageSize":10,"pageNum":1,"data":[{"orderSn":"5010020190702081850082","sellerName":"Chengdu Import and Export Trade Co., Ltd.","buyerName":"Jamaica Purchasing Company","totalPrice":1000000,"currency":1,"paymentType":5,"paymentAgreement":1,"goodsStatus":1,"errorStatus":0,"createTime":"2019-07-02T00:18:50.000+0000","updateTime":"2019-07-02T00:18:50.000+0000","orderTag":0,"takeoverTime":null,"foreignTime":null,"statusBeforeClose":0}]}}

Assert Json Path exists:提取json值,在$后面添加要返回的字段

JMeter元件(六)-断言-6.2JSON断言_JMeter学习_03

执行脚本,断言成功

JMeter元件(六)-断言-6.2JSON断言_JMeter教程_04