Cucumber 重新设置断言失败

Cucumber 重新设置断言失败,cucumber,rest-assured,rest-assured-jsonpath,feature-file,Cucumber,Rest Assured,Rest Assured Jsonpath,Feature File,功能文件片段: 然后messages.type的值应为ERROR 实际服务响应: “信息”:[ { “类型”:“错误” }] 控制台日志: JSON路径messages.type不匹配。 应为:包含“错误”的字符串 实际:[错误] 我已经尝试从功能文件中提到的错误参数中删除双引号,但它不起作用,因为您没有提供所使用的代码,这可能是因为您无法将json响应转换为字符串。请尝试下面的代码,因为它有一个如何将Json转换为字符串的示例 public void jsonPathExample() {

功能文件片段:

然后messages.type的值应为ERROR

实际服务响应: “信息”:[ { “类型”:“错误” }]

控制台日志:

JSON路径messages.type不匹配。 应为:包含“错误”的字符串 实际:[错误]


我已经尝试从功能文件中提到的错误参数中删除双引号,但它不起作用,因为您没有提供所使用的代码,这可能是因为您无法将json响应转换为字符串。请尝试下面的代码,因为它有一个如何将Json转换为字符串的示例

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
    }