繁体   English   中英

列表中的 assertThat 上的 AssertionError

[英]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));
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM