db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Db-derby Wiki] Update of "JunitAssertMessages" by BryanPendleton
Date Sun, 04 Mar 2007 17:03:36 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Db-derby Wiki" for change notification.

The following page has been changed by BryanPendleton:
http://wiki.apache.org/db-derby/JunitAssertMessages

The comment on the change is:
Capture some notes from Dan

New page:
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.

Mime
View raw message