cucumber - RestAssured 断言失败
问题描述
功能文件片段:
那么messages.type的值应该是ERROR
实际服务响应:“消息”:[{“类型”:“错误”}]
控制台日志:
JSON 路径 messages.type 不匹配。预期:包含“ERROR”的字符串实际:[ERROR]
我尝试从功能文件中提到的 ERROR 参数中删除双引号,但它不起作用
解决方案
因为您没有提供您使用的代码,这可能是因为您将 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
}
推荐阅读
- python - 使用 categorical_column_with_vocabulary_list 函数的 num_oov_buckets 选项处理样本外数据中缺失的分类级别
- node.js - MongoDB查询数组基于另一个字段的值
- python - 我无法理解 cross_val_score 和 accuracy_score 之间的区别
- oracle - PL/SQL 动态内容未在 Oracle Apex 中显示
- python - 使用 Python 日志库,如何设置控制台 StreamHandler 的语言环境?
- node.js - 使用 Nodejs、Twilio、Schedule 和 MongoDB 通过电话号码发送带有小时和分钟的 SMS
- python - 为什么当我尝试在 Anaconda 上运行 Spyder 时会出现此错误?
- javascript - 带有 GraphQL 的 Gatsby 中的 JSON
- r - 如何在R中使用不同的下界找到积分
- node.js - NodeJS:我将如何呈现两个页面?