Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

+1 vote
4.9k views
in Technique[技术] by (71.8m points)

使用Junit如何断言两个list相等

用断言好像不行,不能直接比较两个list,难道各自循环比较,这也太麻烦了,取list应该是一个比较通用的操作,看到此问题的人分享一下,自己是如何Junit测试list的


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (1.4k points)
 
Best answer

先比较大小

Assert.assert(expectList.size(), resut.size());

再比较内容,看结果集是否包含所有的期望值,因为大小相同,所以如果全包含就一定是相等的

Assert.assert(result.containAll(expectList));

这个人很懒,什么也没留下...
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...