I'm trying to test a API with Rest Assured. There is an AssertionError when I'm checking a double value.
The code for checking the double:
given().body(getTest()).contentType("application/json\r\n").
when()
.port(port)
.basePath("/fff/test")
.post("insert")
.then()
.assertThat()
.statusCode(200)
.body("versie", equalTo(11.0));
This is the output:
java.lang.AssertionError: 1 expectation failed.
JSON path versie doesn't match.
Expected: <11.0>
Actual: 11.0
When I change the line with .body to:
.body("versie", equalTo(""+11.0));
The output is:
java.lang.AssertionError: 1 expectation failed.
JSON path versie doesn't match.
Expected: 11.0
Actual: 11.0
Does anyone know how I can fix this? Because I really don't know how to solve this.
EDIT
The JSON:
{
"id": 1,
"naam": "Test X",
"versie": 11.0
}
.body("versie", equalTo(11.0f));
This did work for me.
The answer is based on a comment from @StanislavL.
try with a cast (float) into equalTo - .body("value", equalTo((float)12.9)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With