“调用 bsh 方法时出错:eval” 2 个变量的 Beanshell 断言?
Posted
技术标签:
【中文标题】“调用 bsh 方法时出错:eval” 2 个变量的 Beanshell 断言?【英文标题】:"Error invoking bsh method: eval" Beanshell assertion of 2 variables? 【发布时间】:2019-05-07 21:20:38 【问题描述】:我正在尝试使用 beanshell 断言来比较 2 个 JDBC 查询的结果。我看到变量被实际值取代。我不明白为什么在将其存储在局部变量中并进行比较时会出现此错误?
我能够从 vars.get 方法中获取文本,但我认为它没有存储到新的局部变量(var1 和 var2)中,因此会出现空指针异常。
2019-05-07 14:00:26,574 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``try String var1 = vars.get("02H"); String var2 = vars.get("02H"); System.out . . . '' : TargetError
2019-05-07 14:00:26,574 WARN o.a.j.a.BeanShellAssertion: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``try String var1 = vars.get("02H"); String var2 = vars.get("02H"); System.out . . . '' : TargetError
java.lang.NullPointerException: Null Pointer in Method Invocation
at bsh.Name.invokeMethod(Name.java:838) [bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:69) [bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:96) [bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:41) [bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
at bsh.BSHUnaryExpression.eval(BSHUnaryExpression.java:53) ~[bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
at bsh.BSHAssignment.eval(BSHAssignment.java:71) ~[bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
at bsh.BSHBlock.evalBlock(BSHBlock.java:125) [bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
代码:
try
String var1 = vars.get("$ISSTEMP_1");
String var2 = vars.get("$TMUTEMP_1");
Failure = !var1.equals(var2);
if (Failure)
FailureMessage = "Variables are not equal. Expected \"" + var1 + "\" , actual:\"" + var2 + "\"";
catch (Throwable e)
log.error("error in bean shell", e);
throw e;
将值存储在变量中后,我会尝试比较并检查是否存在故障。
Failure = !var1.equals(var2);
我哪里出错了? TIA
【问题讨论】:
【参考方案1】:检查以下代码:-
try
String var1 = vars.get("ISSTEMP_1");
log.info ("var1++++++++++"+var1);
String var2 = vars.get("TMUTEMP_1");
log.info ("var1++++++++++"+var2);
//Failure = !var1.equals(var2);
if (!var1.equals(var2))
log.info("Variables are not equal as Expected");
catch (Exception ex)
log.info("Error in beanshell", ex);
throw ex;
输出 将 log.info 更改为 log.error
希望这会有所帮助。
【讨论】:
以上是关于“调用 bsh 方法时出错:eval” 2 个变量的 Beanshell 断言?的主要内容,如果未能解决你的问题,请参考以下文章