assertEquals(Object o1, Object o2) 是否使用了equals方法 [英] Does assertEquals(Object o1, Object o2) uses the equals method

查看:20
本文介绍了assertEquals(Object o1, Object o2) 是否使用了equals方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

换句话说,assertEquals 是否适用于覆盖 equals

In other words, does assertEquals works with a class that overrides equals

推荐答案

来自 assertEquals 方法的源代码,您可以在 Junit GitHub Repo 上找到:

From the source code of the assertEquals method that you can find on the Junit GitHub Repo:

/**
 * Asserts that two objects are equal. If they are not
 * an AssertionFailedError is thrown with the given message.
 */
static public void assertEquals(String message, Object expected, Object actual) {
    if (expected == null && actual == null) {
        return;
    }
    if (expected != null && expected.equals(actual)) {
        return;
    }
    failNotEquals(message, expected, actual);
}

您可以看到 Junit 正在使用 .equals() 方法.

You can see that Junit is using the .equals() method.

代码片段来自弃用的 Junit 版本.

The code snippet is coming from a deprecated version of Junit.

您可以阅读新"Junit 的来源这里.想法几乎相同,也使用了 .equals() 方法.

You can read about the source of the 'new' Junit here. The idea is pretty much the same, the .equals() method is also used.

这篇关于assertEquals(Object o1, Object o2) 是否使用了equals方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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