Easy way to compare ArrayLists for equality using JUnit?

后端 未结 2 1998
误落风尘
误落风尘 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.

    0 讨论(0)
  • 2021-02-12 06:11

    You might want to check the documentation for List.equals.

    0 讨论(0)
提交回复
热议问题