【发布时间】:2013-08-26 21:04:29
【问题描述】:
尝试比较 2 个列表时,以下行失败:
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
assertThat(
actualDealSummary.getDeals(),
hasItems(expectedDealSummary.getDeals().toArray(new Deal[expectedDealSummary.getDeals().size()])));
使用 JUnit 4.11 和 hamcrest-all (1.3):
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
我只想检查实际列表是否具有预期列表的值,但出现以下错误:
java.lang.AssertionError: 预期:(包含 <SIXRxrImUE> 的集合;以及包含 <RQjVbVRlyG> 的集合;以及包含 <avnKxogdyN> 的集合;) 但是:包含<SIXRxrImUE>的集合;是<SIXRxrImUE>,是<RQjVbVRlyG>,是<avnKxogdyN> 在 org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20) 在 org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8) 在如何使用 hamcrest 的内置 Matchers 来比较 2 个 pojo 列表?
【问题讨论】:
标签: junit4 assertions hamcrest