使用 jmeter(版本5.4.1)工具进行 http请求返回后结果处理时, beanshell中的java代码报错"BeanShellInterpreter: Error invoking bsh method: eval In file: inline evaluation of...",详情如下图:

以下为修改前beanshell 脚本部分代码:

hmGatewayAvg.forEach((key, v) -> {
float percent = (Float.parseFloat(String.valueOf(v))/finalSumValue);//用每个状态的值除以所有状态累加值,获得状态占比率
hmGatewaySatus.put(key,percent);//把单个状态名称,单个状态Percent值放入hashmap中
});
网上查了下,jmeter中的beanshell脚本是不支持java 泛型的。
修改后beanshell代码:
for(Map.Entry entry : hmGatewayAvg.entrySet()){
float v = entry.getValue();
String key = entry.getKey();
float percent = v/finalSumValue;//用每个状态的值除以所有状态累加值,获得状态占比率
hmGatewaySatus.put(key,percent);//把单个状态名称,单个状态Percent值放入hashmap中
}
至此,问题解决。
在使用JMeter5.4.1进行HTTP请求测试时,遇到Beanshell脚本报错,原因是不支持Java泛型。为了解决这个问题,文章中展示了如何修改Beanshell脚本,将使用泛型的代码转换为不使用泛型的等效代码,从而避免错误并成功计算出状态占比率。
1276

被折叠的 条评论
为什么被折叠?



