KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > dtf > MultipleTestResult


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.dtf;
8
9 import junit.framework.AssertionFailedError;
10 import junit.framework.TestCase;
11 import junit.framework.TestResult;
12 import org.jboss.logging.Logger;
13
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 /**
18  * Extends regular JUnit TestResult so can run multiple test methods
19  * within a single TestCase class.
20  *
21  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
22  * @see org.jboss.dtf.MultipleTestCase
23  */

24 public class MultipleTestResult extends TestResult
25 {
26    private static final Logger log = Logger.getLogger(MultipleTestResult.class);
27
28    protected void run(final TestCase test)
29    {
30       if(test instanceof MultipleTestCase)
31       {
32          startTest(test);
33
34          MultipleTestCase mTest = (MultipleTestCase) test;
35          List JavaDoc testMethods = mTest.getTestMethods();
36          Iterator JavaDoc itr = testMethods.iterator();
37          while(itr.hasNext())
38          {
39             try
40             {
41                String JavaDoc methodName = (String JavaDoc) itr.next();
42                log.debug("running test method " + methodName);
43                mTest.runBare(methodName);
44             }
45             catch(AssertionFailedError e)
46             {
47                addFailure(test, e);
48             }
49             catch(ThreadDeath JavaDoc e)
50             { // don't catch ThreadDeath by accident
51
throw e;
52             }
53             catch(Throwable JavaDoc e)
54             {
55                addError(test, e);
56             }
57          }
58          endTest(test);
59
60       }
61       else
62       {
63          super.run(test);
64       }
65    }
66
67 }
Popular Tags