AssertionError on assertThat on a list



我正在从我的黄瓜功能文件发送2行数据

Scenario: Verify the data in the summary
Then the 'Summary' section contains the following data:
| Time Frame: 06/22/2016 20:47:22 UTC to 09/18/2016 17:00:53 UTC          |
| Tabs: 47def , tr1 , e998                                                |

我试图检查我的功能文件每一行的数据是否在从页面中提取的实际文本中找到:

public void sectionContainsTheFollowingData(String section, List<String> expected) {
// text data pulled from the page is stored in 'actual'
List<String> actual = SUMMARY.getSummaryData(section);
for (String cell : expected) {
assertThat(String.format("Did not find %s in data %s", cell, actual), actual.contains(cell));
}

当我执行此操作时,我会得到以下错误:

java.lang.AssertionError: Did not find Time Frame: 06/22/2016 20:47:22 UTC to 09/18/2016 17:00:53 UTC in data [Time Frame: 06/22/2016 20:47:22 UTC to 09/18/2016 17:00:53 UTC Tabs: 47def , tr1 , e998]

我不知道为什么会出现这个错误。我可以看到"时间框架:06/22/2016 20:47:22 UTC到09/18/2016 17:00:53 UTC"是实际的和预期的。我猜我的断言是在寻找完全匹配,但我不想要完全匹配。我只需要功能文件中数据表每一行的文本位于从页面中提取的实际文本中的某个位置。

使用流:

for (String cell : expected) {
assertThat(String.format("Did not find %s in data %s", cell, actual), actual.stream().anyMatch(string -> string.contains(cell));
}

最新更新