Closed ItxiaoDz closed 5 years ago
ObjectCompareUtil.compare(Object target, Object expect) 这个地方本地debug看下,日志结合代码看是逻辑上看是long类型未强转为lL 比对失败原因
你可先试试将 1 强制为 object: !!java.lang.Long 1
@elseifer
你可先试试将 1 强制为 object: !!java.lang.Long 1
这样可以测试通过
@zhuyanli99
ObjectCompareUtil.compare(Object target, Object expect) 这个地方本地debug看下,日志结合代码看是逻辑上看是long类型未强转为lL 比对失败原因
是的,跟踪了一下代码 ObjectCompareUtil.compare(Object target, Object expect)方法中,进入了329行的else if分支
else if (!target.equals(expect)) {
reportStr.append("\ncheck failed, actual value:" + target + "\nExpected value:" + expect);
return false;
}
然后Long的Long的equals方法:
public boolean equals(Object obj) {
if (obj instanceof Long) {
return value == ((Long)obj).longValue();
}
return false;
}
因为expect是Integer类型,所以就直接返回false了。😂
我测试的接口如下:
Long addTeacher(ShopTeacherVO teacher)
就是简单的往数据库中插入一条记录,然后将主键值返回。 测试代码都是通过插件工具生成的。没有做修改。测试用例的yaml配置如下:
设置了期望db数据和期望结果校验。
执行单元测试后,数据库期望校验通过了,但是返回结果的校验失败了。日志如下:
日志上显示actual value和Expected value是一样的,但是被判定为不一致了。