0

I am getting the below exception message while having actual and expected are same. The given reason for the failure seems to be incorrect.

@Test    
            public static void Verify()
            {
                given().
                get("http://services.groupkt.com/country/get/all").
                then().body("RestResponse.messages", equalTo("[Total [249] records 
            found.]"));}

FAILED: Verify
java.lang.AssertionError: 1 expectation failed.
JSON path RestResponse.messages doesn't match.
Expected: [Total [249] records found.]
  Actual: [Total [249] records found.]

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) and much more....
Ankur Singh
  • 1,239
  • 1
  • 8
  • 18
Learner
  • 481
  • 1
  • 15
  • 28
  • 1
    This could mean trailing spaces or some character which make it visually look the same for you. Please check there are no additional spaces or something – Tarun Lalwani Mar 25 '18 at 18:37
  • Actually the output only proves that expected and actual produce the same toString() representation, they are not necessarily of the same type. By the way, of which content type is the response body? – mle Mar 26 '18 at 19:51
  • Response is in JSON format. – Learner Apr 04 '18 at 10:41

2 Answers2

1

@Prasad: Its due to string char I suspect. Try this code it should work

    @Test
public void Verify()
{
    given()
            .get("http://services.groupkt.com/country/get/all")
            .then()
            .body("RestResponse.messages[0]",equalTo("Total [249] records found."));}
Archer
  • 125
  • 1
  • 8
0

Ah because everyone has access to your used URL, I could offer you this solution:

@Test
public void restAssured() {
    RestAssured.given()
            .accept(ContentType.JSON)
            .get("http://services.groupkt.com/country/get/all")
            .then()
            .statusCode(200)
            .body("RestResponse.messages", hasSize(1))
            .body("RestResponse.messages[0]", is("Total [249] records found."))
            .body("RestResponse.messages", is(Arrays.asList("Total [249] records found.")));
}

Watch out for the various assertions possible:

  • size assertion of the list
  • single item assertion
  • complete assertion of the whole list
mle
  • 2,466
  • 1
  • 19
  • 25