ArrayList相等性JUnit测试 [英] ArrayList equality JUnit testing

查看:121
本文介绍了ArrayList相等性JUnit测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆