故事背景
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!運作成功!