intellij-idea - 我想验证特定字段是否存在并使用 RESTAssured API 自动化测试在控制台上打印
问题描述
我想使用 IntelliJ IDea 中的 RESTAssured API 自动化测试来验证特定字段是否存在并在控制台上打印。该字段在数组中并且有多个值。
我也想在控制台中打印该字段。
字段名称为
annualBasePay
,其值为124917
。
我只需要验证字段annualBasePay
[
{
"worker": {
"wID": "137cf520",
"employeeID": "T19"
},
"workerDescription": "Tim Moore",
"workerId": "T19",
"userId": "T19",
"workerType": "Employee",
"jobRelatedInfoType": {
"positionTitle": "Systems Architect 5",
"manager": {
"wID": "1b1696eabe",
"employeeID": "T823"
},
"adjustedServiceDate": "1976-01-16",
"annualBasePay": "124917",
"annualBaseCurrency": null
}
}
]
解决方案
您可以选择以下两种方式之一:
given()
...
.then()
.body("jobRelatedInfoType.annualBasePay", hasItems("124917"));
或者
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItems;
Response res = given()...;
List<String> basePays = JsonPath.with(res.asString()).get("jobRelatedInfoType.annualBasePay");
assertThat(basePays, hasItems("124917"));
推荐阅读
- reactjs - 无法在reactjs jsx中自动完成标签
- python - python调试器:不以交互方式初始化变量
- c++11 - 我初始化 char *str1 = nullptr 并输出到屏幕...但是当我想输出到其他变量时,我收到空屏幕..为什么会这样?
- django - 在 cron 中运行 django manage.py 命令
- react-native - React-Native:无法解析配置“:app:debugCompileClasspath”的所有依赖项
- visual-c++ - 具有多个基类的 Natvis
- mongodb - MEAN Stack Data Model 文档数组或文档数组
- ios - 找不到“FirebaseAnalytics/FIRAnalyticsConfiguration.h”文件
- c++ - 通过 PostThreadMessage 发送 WM_QUIT 时访问冲突
- passport.js - ADFS 证书翻转后无法登录