Issue
I want to use the assertArrayEquals(ArrayList<Token>, ArrayList<Token>)
with these arguments (i.e. arrayList of tokens). But Java tells me I need to create such a method. Is there a way to test for the equality of two arrayLists of whatever type in Junit?
Solution
I want to use the
assertArrayEquals(ArrayList<Token>, ArrayList<Token>)
with these arguments (i.e. arrayList of tokens). But Java tells me I need to create such a method.
It's telling you that you need to create the method because there is no such method in the JUnit library. There isn't such a method in the JUnit library because assertArrayEquals
is for comparing arrays, and and ArrayList
is not an array—it's a List
.
Is there a way to test for the equality of two arrayLists of whatever type in Junit?
You can check the equality of two ArrayLists
(really, any two List
objects) using equals
, so you should be able to use JUnit's assertEquals
method and it will work just fine.
Answered By - DaoWen
Answer Checked By - David Marino (JavaFixing Volunteer)