RestAssured comparing Double with Hamcrest
Asked Answered
T

1

1

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

I have a test:

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

Error is:

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

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 :-)

Tauten answered 8/2, 2017 at 18:51 Comment(0)
C
4

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)
);
Collywobbles answered 4/5, 2017 at 10:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.