通过 vars.putObject 将对象投射到 class 'double'
Cast a object to class 'double' through vars.putObject
在 Jmeter 断言中,主要尝试比较 2 个具有双精度数据类型的变量的值。以下脚本我用来在 double
中投射一个值
double actual = vars.getObject("Merticvalue");
log.info ("Actual MetricValue is found to be " + actual);
double expected=153.60
vars.putObject("expected",expected);
if (vars.getObject("expected") != vars.getObject("actual")) {
props.put("testcaseExecutionStatus",5);
String Status = props.get("testcaseExecutionStatus").toString();
log.info("Status:"+ Status)
return;
}
props.put("testcaseExecutionStatus",1);
String Status = props.get("testcaseExecutionStatus").toString();
log.info("Status:"+ Status)
我收到此错误:
GroovyCastException: Cannot cast object '153.60'
with class 'java.lang.String' to class 'double'
问题是获取 Merticvalue
值并保存为字符串,您可以转换它:
double actual = Double.valueOf(vars.getObject("Merticvalue"));
在 Jmeter 断言中,主要尝试比较 2 个具有双精度数据类型的变量的值。以下脚本我用来在 double
中投射一个值 double actual = vars.getObject("Merticvalue");
log.info ("Actual MetricValue is found to be " + actual);
double expected=153.60
vars.putObject("expected",expected);
if (vars.getObject("expected") != vars.getObject("actual")) {
props.put("testcaseExecutionStatus",5);
String Status = props.get("testcaseExecutionStatus").toString();
log.info("Status:"+ Status)
return;
}
props.put("testcaseExecutionStatus",1);
String Status = props.get("testcaseExecutionStatus").toString();
log.info("Status:"+ Status)
我收到此错误:
GroovyCastException: Cannot cast object '153.60'
with class 'java.lang.String' to class 'double'
问题是获取 Merticvalue
值并保存为字符串,您可以转换它:
double actual = Double.valueOf(vars.getObject("Merticvalue"));