harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jesse Wilson <jessewil...@google.com>
Subject Re: Commit to 5 or 6?
Date Sat, 09 Oct 2010 15:49:27 GMT
On Sat, Oct 9, 2010 at 5:58 AM, Alexei Fedotov <alexei.fedotov@gmail.com>wrote:

> I'm trying to understand best coding practices. Do you mean replacing
> assertTrue to assertEquals for assertions like a = b? isAvailable()
> assertions still may be implemented via assertTrue?
>

Mostly I prefer this:

assertEquals("hotdog", concatenate("hot", "dog"));

Over this:

assertTrue("hotdog".equals(concatenate("hot", "dog")));

If the expression fails, assertEquals() gives more detail in the failure
message. That's pretty non-controversial and we should prefer assertEquals()
when it applies.

It comes up less frequently, but I have some other preferences related to
better detail messages. When comparing arrays, equals() does the wrong
thing. To work around, I compare the string form for primitives:

byte[] actual = ...
byte[] expected = ...
assertEquals(Arrays.toString(actual), Arrays.toString(expected));

And the list form for reference types:

Object[] actual = ...
Object[] expected = ...
assertEquals(Arrays.asList(actual), Arrays.asList(expected));


I'm not actually planning on doing massive scrubbing to change styles or
anything. But when I investigate specific problematic tests, it's helpful to
fix the test to tell me everything that it can.

Cheers,
Jesse

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message