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