> Don't you know about assertArrayEquals() in JUnit ? It's in version 4.5.

I can use that if I know the values are arrays.  The sort of case I'm thinking
of is a data-driven test where I have a big array with a lot of inputs and
the corresponding expected outputs, some but not all of which might be arrays,
including primitive arrays.  For example, the inputs are expressions in a script
language and the outputs are what those expressions should evaluate to.  The 
test
iterates over the array and does assertDeepEquals for each input/output pair.

But it is true that I could use the same new Object[] {x} trick there, in
other words define assertDeepEquals in terms of assertArrayEquals,
to get better failure messages.  The main advantages I see of
deepEquals(Object, Object) are that it avoids allocating a throw-away array
(which is not a concern in unit tests), and more importantly that it is
easier to find than the new Object[] {x} trick.

Éamonn McManus · JMX Spec Lead · http://weblogs.java.net/blog/emcmanus


Ulf Zibis wrote:
Am 09.10.2009 11:30, Eamonn McManus schrieb:
Joseph D. Darcy wrote:
> What are scenarios where this method would be used?

I use a similar method fairly often in unit tests. JUnit's assertEquals doesn't do the right thing if its arguments happen to be arrays, so I use the following
simple if inefficient implementation:

Don't you know about assertArrayEquals() in JUnit ? It's in version 4.5.

-Ulf



Reply via email to