commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Lenz <cml...@gmx.de>
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 RuleTestCase.java, we have the test method:

     public void testObjectCreate1() {

         // Configure the digester as required
         digester.addObjectCreate("employee",
                 "org.apache.commons.digester.Employee");
         digester.addSetProperties("employee");

         // 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",
                 employee.getFirstName());
         assertEquals("Last name is correct",
                 "Last Name",
                 employee.getLastName());
     }

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 gmx.de


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message