I just learned something I should have already known.  Sharing with everyone.

At work, I wrote a set of JUnit tests.  They follow a similar pattern.

@Test public final void getSomeKindOfDataTest(strHome, strServ, startDate, endDate, iAppCtx) {
try {
   AL_al = internalLibrary.getSomeKindOfData(strHome, strServ, startDate, endDate, iAppCtx);
   for (int i = 0; i < AL_al.size(); i++) {
       ... dump out the record
   }// for
   } catch() { fail(); }
}

These methods all began as TEST.java which was written by an early team member. It only exercised all the methods, but didn’t return or otherwise indicate pass or fail.  In other words, you had to eyeball the output to see if there were any problems. When I made JUnit tests out of these, I added the assert() and fail() calls.

I discovered just now that assert() is NOT part of JUnit.  It is a Java keyword that was added in 1.4, and is an assertion that is not run at all, unless you start the JVM with –ea or –enableassertions.  See this for all the gory details: http://download.oracle.com/javase/1.4.2/docs/guide/lang/assert.html

What I had INTENDED to use was assertTrue (AL_al.size() > 0), which IS part of JUnit and is always evaluated.http://junit.sourceforge.net/javadoc/org/junit/Assert.html#assertTrue(boolean)

So I changed my assert() statements to assertTrue(), and suddenly found that 9 out of the 18 tests no longer pass.  If only I had discovered this a day or two ago.

Lesson: assert() is NOT Junit.  Ouch!

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

   
© 2012 LinuxTampa Suffusion theme by Sayontan Sinha