commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Lenz <>
Subject [digester] unit tests swallowing exceptions
Date Wed, 04 Sep 2002 09:08:15 GMT
Hi all,

While experimenting with my proposed refactorings, I've of course been 
running the unit tests again and again ;o), and I've found something 
that disturbed me quite a lot.

For example, in, we have the test method:

     public void testObjectCreate1() {

         // Configure the digester as required

         // Parse our test input.
         Object root = null;
         try {
             root = digester.parse(getInputStream("Test1.xml"));
         } catch (Throwable t) {
             fail("Digester threw IOException: " + t);
         assertNotNull("Digester returned an object", root);
         assertTrue("Digester returned an Employee",
                 root instanceof Employee);
         Employee employee = (Employee) root;
         assertEquals("First name is correct",
                 "First Name",
         assertEquals("Last name is correct",
                 "Last Name",

Obviously, this method swallows all exceptions thrown during the parse 
process, (incorrectly) stating that Digester has thrown an IOException, 
and the only somewhat useful output is the implicit Throwable.toString().

For unexpected exceptions, I usually just add a "throws Exception" to 
the test method signature, so that it eventually gets through to the 
JUnit framework as error. And then, the full stacktrace is available 
when trying to look into the cause of the exception.

Now, the question is, would anyone oppose me changing such test-cases as 
the above so that they no longer swallow the exceptions, but rather pass 
them on?

Christopher Lenz
/=/ cmlenz at

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message