日期:2014-05-18  浏览次数:20787 次

junit的assertEquals问题
我重写了MyObject类的equal方法,得到我想要的结果
x1.equals(x2)==true
但是当我用Assert.assertEquals(x1,x2)却还是failure
达人们帮帮忙解释一下asserEquals都干什么了

------解决方案--------------------
确定不是你自己的equals()方法的问题?assertEquals()就是调用对象的equals()来判断是否相等的

看assertEquals()的源代码:
/**
* 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);
}
/**
* Asserts that two objects are equal. If they are not
* an AssertionFailedError is thrown.
*/
static public void assertEquals(Object expected, Object actual) {
assertEquals(null, expected, actual);
}
------解决方案--------------------
两个object 在内存中的序列是不一样俄