我正在尝试使用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
答案 0 :(得分:0)
检查以下代码:-
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;
}
希望这会有所帮助。