RestAssured比较Double和Hamcrest [英] RestAssured comparing Double with Hamcrest

查看:159
本文介绍了RestAssured比较Double和Hamcrest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个愚蠢的东西,但我真的看不到我缺少什么:

I have a stupid thing, but I really can´t see what am I missing:

我有一个测试:

@Test
public void testeBerechneRendite() {
    get("/rendite?jahresnettomiete=8000&kaufpreis=100000&nebenkosten=500")
    .then().body(is(closeTo(0.079, 0.01)));
}

错误是:

Response body doesn't match expectation.
Expected: is a numeric value within <0.01> of <0.079>
Actual: 0.07960199004975124

它缝我不明白closeTo(double,double) 。根据我的理解,0.069到0.089之间的所有数字都应该有效。如果我完全错了,请澄清一下:-)

It seams I don`t understand the closeTo(double, double). From my understanding all numbers between 0.069 and 0.089 should be valid. If I am totally wrong please clarify :-)

推荐答案

实际值:0.07960199004975124 -这是一个字符串值,这就是您的匹配器不起作用的原因。您需要提取值,将值转换为double并在单独的mathcer中进行比较。

Actual: 0.07960199004975124 - it is a string value, that is why your matcher does not work. You need to extract value, convert into double and compare in separate mathcer.

MatcherAssert.assertThat(
    Double.parseDouble(get("/rendite?jahresnettomiete=8000&kaufpreis=100000&nebenkosten=500")
    .then().extract().jsonPath().getString("args.val")),
    closeTo(0.079, 0.01)
);

这篇关于RestAssured比较Double和Hamcrest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆