Easy way to compare ArrayLists for equality using JUnit?

后端 未结 2 1997
误落风尘
误落风尘 2021-02-12 05:22

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?

2条回答
  •  长发绾君心
    2021-02-12 06:09

    You need to do nothing special for list equality, just use assertEquals.

    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.

提交回复
热议问题