• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package junit.extensions;
2 
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5 import junit.framework.TestResult;
6 import junit.framework.TestSuite;
7 
8 /**
9  * A TestSuite for active Tests. It runs each
10  * test in a separate thread and waits until all
11  * threads have terminated.
12  * -- Aarhus Radisson Scandinavian Center 11th floor
13  */
14 public class ActiveTestSuite extends TestSuite {
15     private volatile int fActiveTestDeathCount;
16 
ActiveTestSuite()17     public ActiveTestSuite() {
18     }
19 
ActiveTestSuite(Class<? extends TestCase> theClass)20     public ActiveTestSuite(Class<? extends TestCase> theClass) {
21         super(theClass);
22     }
23 
ActiveTestSuite(String name)24     public ActiveTestSuite(String name) {
25         super(name);
26     }
27 
ActiveTestSuite(Class<? extends TestCase> theClass, String name)28     public ActiveTestSuite(Class<? extends TestCase> theClass, String name) {
29         super(theClass, name);
30     }
31 
32     @Override
run(TestResult result)33     public void run(TestResult result) {
34         fActiveTestDeathCount = 0;
35         super.run(result);
36         waitUntilFinished();
37     }
38 
39     @Override
runTest(final Test test, final TestResult result)40     public void runTest(final Test test, final TestResult result) {
41         Thread t = new Thread() {
42             @Override
43             public void run() {
44                 try {
45                     // inlined due to limitation in VA/Java
46                     //ActiveTestSuite.super.runTest(test, result);
47                     test.run(result);
48                 } finally {
49                     ActiveTestSuite.this.runFinished();
50                 }
51             }
52         };
53         t.start();
54     }
55 
waitUntilFinished()56     synchronized void waitUntilFinished() {
57         while (fActiveTestDeathCount < testCount()) {
58             try {
59                 wait();
60             } catch (InterruptedException e) {
61                 return; // ignore
62             }
63         }
64     }
65 
runFinished()66     synchronized public void runFinished() {
67         fActiveTestDeathCount++;
68         notifyAll();
69     }
70 }