jmeter断言接口响应字段大小

一,有时候断言需要判断接口返回某个字段值是否大于或者小于预期值,此时断言需要用到BeanShell断言

写法如下:

import com.alibaba.fastjson.JSONObject;

// String expiresin=vars.get("body.expiresin");
String resp = prev.getResponseDataAsString();
JSONObject respJson = new JSONObject(resp);
int expiresin = respJson.get("body").getInteger("expiresin");
if(expiresin > =0){
Failure = false;
}else{
Failure = true;
FailureMessage = "失败, " + expiresin + "不 >= 0 ";
}

二、添加依赖包fastjson

三、添加BeanShell断言控件

断言内容为接口返回expiresin字段,需要用fastjson提取出该值进行进行判断

原文地址:https://www.cnblogs.com/yanpan/p/10655657.html