cucumber - 通过场景大纲断言空值
问题描述
我正在尝试通过下面的功能文件断言 JSON 响应空值
Scenario Outline: GET incident notifications
Given I made a GET request for incident notifications for the "<incident>"
Then I should be able to see "<NotificationID>", "<DateTime>", "<ActionID>", "<Subject>", "<CreatedBy>","<Notes>"
Examples:
| incident |NotificationID|DateTime |ActionID|Subject |CreatedBy|Notes|
| 399 | 211 |2017-11-28T14:30:11.01|0 |Logged with Openreach| | |
| 400 | 2112 |2017-11-28T14:35:11.01|1 |Processed at Openreach|Agent | AgentNotes |
这是我的步骤定义-
assertThat(webModel.getRestServices().response.getBody().path("CreatedBy[0]"),is(CreatedBy));
assertThat(webModel.getRestServices().response.getBody().path("Notes[0]"),is(Notes));
这是我得到的错误断言错误-
java.lang.AssertionError:
Expected: is ""
but: was null
我可以通过断言来让这个东西工作,nullValue()
但是第二次运行将失败,因为它必须从功能文件中获取参数。任何帮助将不胜感激。
解决方案
当我们在特征文件中将任何参数设为空白时,将其视为空。这就是您收到此错误的原因,因为它正在将 null 与字符串进行比较。我们可以通过在断言之前进行空或空检查来解决这个问题。如果值为 null,它将跳过断言,否则将断言。
推荐阅读
- c# - Google API 身份验证服务器端
- python - 删除列表列表中的所有重复项(不包括原始项)
- postgresql - 在发布前批准对实体的修改
- database - SQLite 使用来自不同表的数据查找股票数量
- javascript - 使用redux,如何避免在进行新的API调用之前渲染旧的状态数据?
- spring-boot - 使用 Broadleaf 进行 Spring 社交登录
- typescript - 为什么 Typescript 不将对象键缩小为字符串
- php - Codeigniter 在单个语句中调用多个函数
- nativescript - 每次添加新屏幕时,Nativescript 应用程序的大小都会增加
- mysql - 如何确保首先评估 WHERE 中的子查询?