使用JUnit比较ArrayLists是否相等的简单方法? [英] Easy way to compare ArrayLists for equality using JUnit?

查看:102
本文介绍了使用JUnit比较ArrayLists是否相等的简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JUnit比较ArrayLists是否相等的简单方法是什么?我需要实现相等接口吗?或者是否有一个简单的JUnit方法,使其更容易?

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?

推荐答案

你需要对列表相等没什么特别的,只需使用assertEquals 。

You need to do nothing special for list equality, just use assertEquals.

ArrayList和其他列表通过使用对象的equals()方法检查列表的相应位置中的所有对象是否相等来实现equals()。因此,您可能需要检查列表中的对象是否正确等于。

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.

这篇关于使用JUnit比较ArrayLists是否相等的简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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