Assert.assertEquals()无法用于自定义类对象 [英] Assert.assertEquals() fails for custom class objects

查看:292
本文介绍了Assert.assertEquals()无法用于自定义类对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使我有两个自定义类的数据对象,它们等于w.r.t所有变量,但assertEquals()方法都失败了。我在这里缺少什么?

Even though I have two data objects of a custom class which are equal w.r.t all the variables, assertEquals() method is failing. What am I missing here?

推荐答案

比较以检查在equals()函数的帮助下是否发生了等于。您需要在自定义类中覆盖此方法。

Comparison to check if its equals are not happens with the help of the equals() function. You need to override this method in your custom class.

public boolean equals(Object obj) { }

请同时确保覆盖hashCode()方法。

Please also make sure you override hashCode() method as well.

这篇关于Assert.assertEquals()无法用于自定义类对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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