Easy way to compare ArrayLists for equality using JUnit?

后端 未结 2 1675
半阙折子戏
半阙折子戏 2021-02-12 05:46

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:06

    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.

提交回复
热议问题