通过场景大纲断言空值
Asserting a null value via a Scenario outline
我正在尝试通过下面的功能文件断言一个 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 与 String 进行比较。
我们可以通过在断言之前进行 null 或空检查来解决这个问题。如果该值为 null,它将跳过断言,否则它将断言。
我正在尝试通过下面的功能文件断言一个 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 与 String 进行比较。 我们可以通过在断言之前进行 null 或空检查来解决这个问题。如果该值为 null,它将跳过断言,否则它将断言。