我在JMeter中有这个方案:
获取余额值(GET)放入var mainBalance
重新充电(POST)
验证结果余额(GET) - 输入var updatedBalance ,例如 updatedBalance mainBalance + 10 $
所有值必须是float类型。
I m stuck at the last step: I've put a BeanShell assertion but doesn't work. It think that i get the values in the wrong way and also i don
按照JMeter的要求进行计算。我也试过 vars.get(String.valueOf(“mainBalance”))
float a = new float(vars.get("mainBalance"));
float b = new float(vars.get("updatedBalance"));
if(b != (a + 10)) {
Failure = true;
}
这是日志错误:
断言错误:是的 断言失败:错误 断言失败消息:org.apache.jorphan.util.JMeterException:调用bsh方法时出错:eval在文件中:内联评估:``float a = new float(“mainBalance”); float b = new float(“updatedBalance”); if(b ...''遇到'(“第1行,第20栏。
答案 0 :(得分:1)
相关代码如下:
def a = new BigDecimal(vars.get('mainBalance'))
def b = new BigDecimal(vars.get('updatedBalance'))
if (b.compareTo(a.add(new BigDecimal('10'))) != 0) {
AssertionResult.setFailure(true)
}