Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rest Assured: JSON path body doesn't match doubles

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
}
like image 204
476rick Avatar asked Jun 12 '17 13:06

476rick


2 Answers

.body("versie", equalTo(11.0f));

This did work for me.
The answer is based on a comment from @StanislavL.

like image 91
476rick Avatar answered Sep 18 '22 15:09

476rick


try with a cast (float) into equalTo - .body("value", equalTo((float)12.9)

like image 44
Joseph_lpz Avatar answered Sep 19 '22 15:09

Joseph_lpz