ArrayList相等性JUnit测试 [英] ArrayList equality JUnit testing
问题描述
我想将assertArrayEquals(ArrayList<Token>, ArrayList<Token>)
与这些参数一起使用(即tokens的arrayList).但是Java告诉我我需要创建这样的方法.有没有一种方法可以测试Junit中任何类型的两个arrayLists的相等性?
我想将
assertArrayEquals(ArrayList<Token>, ArrayList<Token>)
与这些参数一起使用(即tokens的arrayList).但是Java告诉我我需要创建这样的方法.
这是在告诉您需要创建方法,因为JUnit库中没有这样的方法. JUnit库中没有这样的方法,因为assertArrayEquals
用于比较数组,而ArrayList
不是不是数组-它是List
.
有没有一种方法可以测试Junit中两个不同类型的arrayList的相等性?
您可以使用 解决方案
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.
这篇关于ArrayList相等性JUnit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!