Assert.assertEquals() methods for primitive arrays?

241 views
Skip to first unread message

Tim Fennell

unread,
Mar 12, 2006, 1:46:00 PM3/12/06
to testng-users
Hi Cedric, All,

I was just coding away on a bunch of tests that generated primitive
arrays (int[] in this case) and was meriily going along doing:
Assert.assertEquals(arr1, arr2);

When I ran the test I got a failure and on poking a little bit it's
obvious why. Actually the failure message was a little bit of a hint.
The message looked like this:
java.lang.AssertionError: expected:<[I@20dcb7> but was:<[I@7aa2a8>

Clearly the arrays were getting no special treatment. In fact the
method being called was assertEqual(Object, Object) and so it would
seem it was doing a memory/JVM id equality check.

So I was wondering, is there a particular reason that there are not
assertEquals() methods for arrays of each of the primitive types?
Admittedly it's not that hard to write:
Assert.assertTrue( Arrays.equals(arr1, arr2) );

But I think having the methods on Assert would reduce confusion, and
allow for the output of better default failure messages like:
java.lang.AssertionError: expected:[1,2,3] but was:[3,2,1]

Just a suggestion.

-t

Alexandru Popescu

unread,
Mar 12, 2006, 1:57:46 PM3/12/06
to testng...@googlegroups.com
No particular reason I can remember. Probably we didn't need it till now :-).

./alex
--
.w( the_mindstorm )p.

Tim Fennell

unread,
Mar 12, 2006, 1:59:10 PM3/12/06
to testng...@googlegroups.com
Fair enough.  Should I just go ahead and log a JIRA item for it?
-t

Alexandru Popescu

unread,
Mar 12, 2006, 2:09:32 PM3/12/06
to testng...@googlegroups.com
Yes, go on. i can probably add it quite soon.
Reply all
Reply to author
Forward
0 new messages