0

I have been playing around testing an api I've looked for ID 24 in my test and my actual and expected are the same I'm assuming I'm using the incorrect syntax where I have .body what should I put in place instead?

    @Test
public void test_get_userid() {

    given().
            when().
            get("http://bpdts-test-app-v2.herokuapp.com/user/24").
            then().
            assertThat().
            statusCode(200).
            and().
            contentType(ContentType.JSON).
            and().
            body("id", equalTo("24"));
}

java.lang.AssertionError: 1 expectation failed.
JSON path id doesn't match.
Expected: 24
  Actual: 24

2 Answers2

1

The provided JSON object has the number 24 under the key "id". It is not a JSON string, that would be "24".

Have you tried equalTo(24) ? As in a number literal, not a string literal.

Hawk
  • 2,042
  • 8
  • 16
0

Type of id is an integer, not String.

Correct Answer is

given().when().get("http://bpdts-test-app-v2.herokuapp.com/user/24").then().assertThat().statusCode(200).and()
            .contentType(ContentType.JSON).and().body("id", equalTo(24));

You can test using the following code which will give the type of the value as "java.lang.Integer"

Class<? extends Object> m1 = given().when().get("http://bpdts-test-app-v2.herokuapp.com/user/24").getBody()
            .jsonPath().get("id").getClass();
    System.out.println(m1);
Arun Nair
  • 425
  • 3
  • 11