使用JUnit比较ArrayLists是否相等的简单方法? [英] Easy way to compare ArrayLists for equality using JUnit?
问题描述
使用JUnit比较ArrayLists是否相等的简单方法是什么?我需要实现相等接口吗?或者是否有一个简单的JUnit方法,使其更容易?
What is an easy way to compare ArrayLists for equality using JUnit? Do I need to implement the equality interface? Or is there a simple JUnit method that makes it easier?
推荐答案
你需要对列表相等没什么特别的,只需使用assertEquals 。
You need to do nothing special for list equality, just use assertEquals.
ArrayList和其他列表通过使用对象的equals()方法检查列表的相应位置中的所有对象是否相等来实现equals()。因此,您可能需要检查列表中的对象是否正确等于。
ArrayList and other lists implement equals() by checking that all objects in the corresponding positions of the lists are equal, using the equals() method of the objects. So you might want to check that the objects in the list implement equals correctly.
这篇关于使用JUnit比较ArrayLists是否相等的简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!