Differences between revisions 1 and 2
Revision 1 as of 2007-03-04 17:03:35
Size: 1227
Comment: Capture some notes from Dan
Revision 2 as of 2009-09-20 22:11:26
Size: 1227
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

This style of code can be expensive at runtime:

   for (int i = 0; i < count; i++) {
      assertEquals("Testing at iteration " + i, f(i), g(i));

The issue is the message will be created 'count' times even though it is never used. This takes up cpu time and garbage collection time.

In the Derby sanity code this style was a problem, causing extended test running time, so the encouraged practice (for Derby sanity checks) is

  if (SanityManager.ASSERT)
     if (X != Y)
        SanityManager.THROWASSERT("Value should be " + X + " is " + Y);

rather than

  if (SanityManager.ASSERT)
     SanityManager.ASSERT(X == Y, "Value should be " + X + " is " + Y);

We're still deciding what the best practice for JUnit tests should be, but based upon past experience when we see a loop with a complex iteration specific assert message we worry about execution time.

In some cases the message can be fixed, e.g. this coding style should not be encouraged:

  assertEquals("Expected " + X + " to be the equal to " + Y, X, Y);

This is because the JUnit mechanism will print out the value of X and Y, so no need to repeat it in a generated message.

JunitAssertMessages (last edited 2009-09-20 22:11:26 by localhost)