预期和实际匹配,但测试未通过。

huangapple go评论65阅读模式
英文:

Expected and actual matching but test is failing

问题

使用 rest-assured 调用基本 rest 服务:

given().get(baseUrl + "/base/")
    .then()
    .statusCode(200)
    .body("size()", is(2))
    .body("meanPerDay", equalTo(1.5))

返回:

java.lang.AssertionError: 1 个期望失败。
JSON 路径 meanPerDay 不匹配。
期望值:<1.5>
实际值:1.5

baseUrl + "/base/" 的有效负载为:

{
    "meanPerDay": 1.5,
    "stdPerDay": 0.5
}

如果我将 .body("meanPerDay", equalTo(1.5)) 替换为 .body("meanPerDay", equalTo("1.5"))

失败信息为:

java.lang.AssertionError: 1 个期望失败。
JSON 路径 meanPerDay 不匹配。
期望值:1.5
实际值:1.5

我没有正确访问 meanPerDay 属性吗?

测试发现属性值,因为Expected 值为 1.5?

英文:

Using rest-assured to invoke a base rest service with:

  given().get(baseUrl + &quot;/base/&quot;)
                .then()
                .statusCode(200)
                .body(&quot;size()&quot;, is(2))
                .body(&quot;meanPerDay&quot;, equalTo(1.5))

returns :

java.lang.AssertionError: 1 expectation failed.
JSON path meanPerDay doesn&#39;t match.
Expected: &lt;1.5&gt;
  Actual: 1.5

The payload of baseUrl + &quot;/base/&quot; is:

{
    &quot;meanPerDay&quot;: 1.5,
    &quot;stdPerDay&quot;: 0.5
}

If I replace .body("meanPerDay", equalTo(1.5)) with .body("meanPerDay", equalTo("1.5"))

the failure is:

java.lang.AssertionError: 1 expectation failed.
JSON path meanPerDay doesn&#39;t match.
Expected: 1.5
  Actual: 1.5

I'm not accessing the meanPerDay attribute correctly?

The test is finding the attribute value as the Expected is value 1.5?

答案1

得分: 1

以下是浮点数:

{
    "meanPerDay": 1.5,
    "stdPerDay": 0.5
}

然而,以下的测试是与一个 "double" 进行比较:

.body("meanPerDay", equalTo(1.5))

因此,你可以尝试这样写:

.body("meanPerDay", equalTo(1.5f))
英文:

The below numbers are floating point

{
    &quot;meanPerDay&quot;: 1.5,
    &quot;stdPerDay&quot;: 0.5
}

, however, the following test is comparing with a "double":

 .body(&quot;meanPerDay&quot;, equalTo(1.5))

So, you can try this:

 .body(&quot;meanPerDay&quot;, equalTo(1.5f))

huangapple
  • 本文由 发表于 2020年9月3日 17:13:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/63720466.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定