JUnit 4比较集 [英] JUnit 4 compare Sets
本文介绍了JUnit 4比较集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您如何简洁地断言Collection
元素的相等性,特别是JUnit 4中的Set
?
How would you succinctly assert the equality of Collection
elements, specifically a Set
in JUnit 4?
推荐答案
You can assert that the two Set
s are equal to one another, which invokes the Set
equals()
method.
public class SimpleTest {
private Set<String> setA;
private Set<String> setB;
@Before
public void setUp() {
setA = new HashSet<String>();
setA.add("Testing...");
setB = new HashSet<String>();
setB.add("Testing...");
}
@Test
public void testEqualSets() {
assertEquals( setA, setB );
}
}
如果两个Set
的大小相同且包含相同的元素,则此@Test
将通过.
This @Test
will pass if the two Set
s are the same size and contain the same elements.
这篇关于JUnit 4比较集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文