I quote this post from exubero's entry. I think this entry will benefit everyone who is doing a unit test:
There are a large number of different methods beginning with assert defined in Junit's Assert class. Each of these methods has slightly different arguments and semantics about what they are asserting.
The following shows some irregular uses of assertTrue:
assertTrue("Objects must be the same", expected == actual);
assertTrue("Objects must be equal", expected.equals(actual));
assertTrue("Object must be null", actual == null);
assertTrue("Object must not be null", actual != null);
Some unit testing experts pointed out that the above code could be better written as:
assertSame("Objects must be the same", expected, actual);
assertEquals("Objects must be equal", expected, actual);
assertNull("Object must be null", actual);
assertNotNull("Object must not be null", actual);
One of the advantage of using the appropriate 'assertXXX()' will increase the readability of the unit test. Can anyone point out what other benefit of using the appropriate 'assertXXX()' ?