故事背景
jmeter中创建一个BeanShell Sampler。编写了一个BeanShell Sampler脚本。结果,报错了…… 代码如下:
String s = "s";
String y = "y";
boolean result = s.equals(y);
vars.put("result2",result);
如图:

报错如下:
详细报错代码:
Error Count:
Response code:
Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``String s = "s"; String y = "y"; boolean result = s.equals(y); vars.put("result2" . . . '' : Error in method invocation: Method put( java.lang.String, boolean ) not found in class'org.apache.jmeter.threads.JMeterVariables'
问题解决思路
1、看报错信息
2、根据报错内容调试代码
尝试解决问题
报错的提示如下
没有找到put( java.lang.String, boolean )这个方法。
大胆猜测,put的value应该是String。验证猜想:
运行结果:
Good!运行成功!