SI'm试图测试可能= null的JSON值。Jmeter:使用Beanshell Assertion测试null JSON值
首先我试着用jp @ gc - JSON Path Assertion。但是如果遇到空值,那么它不会返回任何东西或定义变量。
所以我试图让它像这样的工作:
- 使用JP @ GC - JSON路径抽出来尝试值提取到一个变量。
- 使用Beanshell断言来测试以查看变量是否存在或具有空值
- 如果变量不存在或存在并且具有空值,那么我知道JSON值为空。
我没有写使用JMeter之前的任何脚本,所以我可能会做一些显然是错误的,但这里是我在BeanShell的断言已经试过:
try {
String myValue = vars.get("myValue");
log.info("myValue =" + myValue);
}
catch (e) {
log.info("caught exception: "+e);
String myValue = null;
}
if (myValue.length() > 0 && myValue != 0){
Failure = true;
FailureMessage = "myValue was " + myValue + ".";
}
else{
Failure = false;
}
对于这个测试,一个空值实际上通过了测试。
我遇到的问题是try/catch块不起作用。相反,我看到下面的消息在日志中:
jmeter.assertions.BeanShellAssertion: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.apache.jmeter.util.JMeterUtils; try { //myValue = JMeterUtils.get . . . '' : Attempt to resolve method: length() on undefined variable or class name: myValue
谁能告诉我,我做错了什么和/或如何得到一个空的JSON值这个测试工作?
你可以显示服务器的响应? – olyv