JUnit 4比较集合 [英] JUnit 4 compare Collections
本文介绍了JUnit 4比较集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何简洁地断言 collections
元素的等同性,特别是中的
? Set
JUnit 4
How would you succinctly assert the equality of collections
elements, specifically a Set
in JUnit 4
?
推荐答案
您可以断言两个集合彼此相等调用Set equals()方法。
You can just assert that the two Sets 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 );
}
}
大小并包含相同的元素。
This test will pass if the two Sets are the same size and contain the same elements.
这篇关于JUnit 4比较集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文