0

我收到以下异常消息,而实际和预期是相同的。给定的失败原因似乎不正确。

@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....
4

2 回答 2

1

@Prasad:这是由于我怀疑是字符串字符。试试这个代码它应该可以工作

    @Test
public void Verify()
{
    given()
            .get("http://services.groupkt.com/country/get/all")
            .then()
            .body("RestResponse.messages[0]",equalTo("Total [249] records found."));}
于 2018-03-26T13:47:17.850 回答
0

啊,因为每个人都可以访问您使用的 URL,所以我可以为您提供以下解决方案:

@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.")));
}

注意可能的各种断言:

  • 列表的大小断言
  • 单项断言
  • 整个列表的完整断言
于 2018-03-26T19:54:55.220 回答