简体   繁体   English

列表中的 assertThat 上的 AssertionError

[英]AssertionError on assertThat on a list

I'm sending 2 rows of data from my cucumber feature file:我正在从我的黄瓜特征文件发送 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                                                |

I'm trying to check that the data from each row of my feature file is found in the actual text that was pulled from the page:我正在尝试检查是否在从页面中提取的实际文本中找到了来自我的特征文件每一行的数据:

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));
        }

When I execute this I get the following error:当我执行此操作时,出现以下错误:

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]

I'm not sure why I get this error.我不确定为什么会收到此错误。 I can see that "Time Frame: 06/22/2016 20:47:22 UTC to 09/18/2016 17:00:53 UTC" is in both the actual and expected.我可以看到“时间框架:06/22/2016 20:47:22 UTC 到 09/18/2016 17:00:53 UTC”在实际和预期中。 I'm guessing that my assertion is looking for an exact match, but I don't want an exact match.我猜我的断言正在寻找完全匹配,但我不想要完全匹配。 I just need the text from each row of the data table in the feature file to be somewhere within the actual text pulled from the page.我只需要特征文件中数据表每一行的文本位于从页面中提取的实际文本中的某个位置。

With streams:使用流:

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