RestAssured断言失败

问题描述 投票:0回答:1

功能文件摘要:

然后,messages.type的值应为ERROR

实际服务响应:“消息”:[{“ type”:“ ERROR”}]

控制台日志:

JSON路径messages.type不匹配。预期:包含“ ERROR”的字符串实际:[ERROR]

我已经尝试从功能文件中提到的ERROR参数中删除双引号,但这是行不通的

cucumber rest-assured rest-assured-jsonpath feature-file
1个回答
0
投票

由于您未提供使用的代码,这可能是由于您将json响应转换为String的事实。请尝试下面的代码,因为它有一个如何将Json转换为String的示例。

public void jsonPathExample() {
        Response response=given().contentType(ContentType.JSON).get("http://localhost:3000/posts");
          //we need to convert response as a String 
        JsonPath jsonPath = new JsonPath(response.asString());
        String actualtype = jsonPath.getString("type");
//Then do your assertion
    }
© www.soinside.com 2019 - 2024. All rights reserved.