Java junit.framework.AssertionFailedError 在 String[] 上执行 assertEquals 时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19041311/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
junit.framework.AssertionFailedError while doing assertEquals on String[]
提问by Alagappan Ramu
I have the following class which returns a list of strings.
我有以下类,它返回一个字符串列表。
public static String[] parseLinks(String text) {
String[] result = new String[] {"",""};
return result;
}
But when I do an assertEquals on the result,
但是当我对结果执行 assertEquals 时,
assertEquals(new String[]{"",""}, parseLinks(""));
I get the following error:
我收到以下错误:
Exception in thread "main" junit.framework.AssertionFailedError: expected: <[Ljava.lang.String;@2352544e> but was:<[Ljava.lang.String;@721cdeff>
at junit.framework.Assert.fail(Assert.java:57)
at junit.framework.Assert.failNotEquals(Assert.java:329)
at junit.framework.Assert.assertEquals(Assert.java:78)
at junit.framework.Assert.assertEquals(Assert.java:86)
at junit.framework.TestCase.assertEquals(TestCase.java:253)
How do I go about fixing this? Please let me know if there is any other additional information that I have to provide.
我该如何解决这个问题?如果我必须提供任何其他额外信息,请告诉我。
采纳答案by Jeff Storey
You're comparing two different Array objects. You can use assertArrayEquals
to compare arrays instead.
您正在比较两个不同的 Array 对象。您可以使用assertArrayEquals
来比较数组。