Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

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

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


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

1 Reply

0 votes
by (1.4k points)
 
Best reply

先比较大小

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

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

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

这个人很懒,什么也没留下...
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...