功能文件片段:
则messages.type的值应为ERROR
实际服务响应:"messages":{ "type":"ERROR“}
控制台日志:
JSON路径messages.type不匹配。预期:包含" ERROR“的字符串实际:错误
我已尝试从要素文件中提到的错误参数中删除双引号,但不起作用
发布于 2019-12-27 08:49:59
SInce您没有提供您使用的代码,这可能是因为您没有将json响应转换为字符串。请尝试使用下面的代码,因为它有一个如何将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
}https://stackoverflow.com/questions/59493722
复制相似问题