在Jmeter断言中,主要尝试比较具有双精度数据类型的2个变量的值。 以下脚本我用来在双精度中转换值
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"));