BeanShell Sampler调用添加的java方法
1、BeanShell Sampler里添加java方法
public static String test()
{vars.put("jmeter1","111");vars.put("jmeter2","222");vars.put("jmeter3","333");vars.put("jmeter4","444");vars.put("jmeter5","555");return "Success";
}
test();
2、BeanShell Sampler响应结果为Success,说明调用成功了
4、查看debug响应数据,jmeter1=111
jmeter2=222
jmeter3=333
jmeter4=444
jmeter5=555,确认BeanShell Sampler调用java文件执行成功
5、调用BeanShell Sampler里声明的变量jmeter1
6、HTTP请求调用传参值正确为{"a":111,"b":5}
BeanShell Sampler调用引入的java文件
1、新建java文件C:\\Users\\wangli\\Desktop\\Myclass.java
2、BeanShell Sampler里引导java文件
source("C:\\Users\\wangli\\Desktop\\Myclass.java");
int res = new Myclass().add(2,3);
vars.put("add",res.toString())
3、HTTP请求调用传参为{"a":${jmeter1},"b":${add}}
4、查看debug响应数据,add=5,确认BeanShell Sampler引入java文件执行成功
5、HTTP请求调用传参正确为{"a":111,"b":5}