相关疑难解决方法(0)

JUnit 4比较集

你会如何简洁地断言Collection元素的相等性,特别是Set在JUnit 4中?

java collections junit unit-testing

96
推荐指数
4
解决办法
9万
查看次数

为什么这段代码没有尝试使用Hamcrest的hasItems编译?

为什么这不编译,哦,该怎么办?

import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.hasItems;

ArrayList<Integer> actual = new ArrayList<Integer>();
ArrayList<Integer> expected = new ArrayList<Integer>();
actual.add(1);
expected.add(2);
assertThat(actual, hasItems(expected));
Run Code Online (Sandbox Code Playgroud)

从评论中复制的错误:

cannot find symbol method assertThat(java.util.ArrayList<java.lang.Integer>, org.hamcreset.Matcher<java.lang.Iterable<java.util.ArrayList<java.lang.Integer>>>)
Run Code Online (Sandbox Code Playgroud)

java junit unit-testing hamcrest matcher

55
推荐指数
3
解决办法
8万
查看次数

Hamcrest的hasItems,contains和containsInAnyOrder有何不同?

Hamcrest提供了许多用于断言集合内容的匹配器.所有这些案件都通过:

Collection<String> c = ImmutableList.of("one", "two", "three");
assertThat(c, hasItems("one", "two", "three");
assertThat(c, contains("one", "two", "three");
assertThat(c, containsInAnyOrder("one", "two", "three");
Run Code Online (Sandbox Code Playgroud)

如何hasItems,contains以及containsInAnyOrder有什么不同?

hamcrest

50
推荐指数
1
解决办法
3万
查看次数

标签 统计

hamcrest ×2

java ×2

junit ×2

unit-testing ×2

collections ×1

matcher ×1