我正在尝试将 JSON 中的\assert double 与java 原始double 值进行比较。
正确的做法是什么?
我用简单而常规的方式来做到这一点,使用Matchers.equalTo
方法见下文
public class A{
private static double someJavaDouble = 12
}
given().
header(.....).
when().
get(url).
then().
statusCode(200)
body("value", Matchers.equalTo(someJavaDouble))
的响应get(url)
是 JSON:
{
"success": true,
"currentValue": 12.0
}
在上面的代码中我得到这个错误:
JSON path currentValue doesn't match.
Expected: <12.0>
Actual: 12.0
附注
它有效,如果
body("value", Matchers.equalTo(12f))
RestAssured 将数字解析为Float
默认情况下。
基于github 问题 1315 https://github.com/rest-assured/rest-assured/issues/1315您可以将其配置为将其解析为 Double:
JsonConfig jsonConfig = JsonConfig.jsonConfig()
.numberReturnType(JsonPathConfig.NumberReturnType.DOUBLE);
RestAssured.config = RestAssured.config()
.jsonConfig(jsonConfig);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)