112 |
|
* methods as there are exceptions the method can throw. Sometimes |
113 |
|
* there are multiple tests per JSR166 method when the different |
114 |
|
* "normal" behaviors differ significantly. And sometimes testcases |
115 |
< |
* cover multiple methods when they cannot be tested in |
116 |
< |
* isolation. |
115 |
> |
* cover multiple methods when they cannot be tested in isolation. |
116 |
|
* |
117 |
|
* <li>The documentation style for testcases is to provide as javadoc |
118 |
|
* a simple sentence or two describing the property that the testcase |
175 |
|
private static final int suiteRuns = |
176 |
|
Integer.getInteger("jsr166.suiteRuns", 1); |
177 |
|
|
178 |
+ |
/** |
179 |
+ |
* The scaling factor to apply to standard delays used in tests. |
180 |
+ |
*/ |
181 |
+ |
private static final int delayFactor = |
182 |
+ |
Integer.getInteger("jsr166.delay.factor", 1); |
183 |
+ |
|
184 |
|
public JSR166TestCase() { super(); } |
185 |
|
public JSR166TestCase(String name) { super(name); } |
186 |
|
|
278 |
|
main(suite(), args); |
279 |
|
} |
280 |
|
|
281 |
+ |
static class PithyResultPrinter extends junit.textui.ResultPrinter { |
282 |
+ |
PithyResultPrinter(java.io.PrintStream writer) { super(writer); } |
283 |
+ |
long runTime; |
284 |
+ |
public void startTest(Test test) {} |
285 |
+ |
protected void printHeader(long runTime) { |
286 |
+ |
this.runTime = runTime; // defer printing for later |
287 |
+ |
} |
288 |
+ |
protected void printFooter(TestResult result) { |
289 |
+ |
if (result.wasSuccessful()) { |
290 |
+ |
getWriter().println("OK (" + result.runCount() + " tests)" |
291 |
+ |
+ " Time: " + elapsedTimeAsString(runTime)); |
292 |
+ |
} else { |
293 |
+ |
getWriter().println("Time: " + elapsedTimeAsString(runTime)); |
294 |
+ |
super.printFooter(result); |
295 |
+ |
} |
296 |
+ |
} |
297 |
+ |
} |
298 |
+ |
|
299 |
+ |
/** |
300 |
+ |
* Returns a TestRunner that doesn't bother with unnecessary |
301 |
+ |
* fluff, like printing a "." for each test case. |
302 |
+ |
*/ |
303 |
+ |
static junit.textui.TestRunner newPithyTestRunner() { |
304 |
+ |
junit.textui.TestRunner runner = new junit.textui.TestRunner(); |
305 |
+ |
runner.setPrinter(new PithyResultPrinter(System.out)); |
306 |
+ |
return runner; |
307 |
+ |
} |
308 |
+ |
|
309 |
|
/** |
310 |
|
* Runs all unit tests in the given test suite. |
311 |
|
* Actual behavior influenced by jsr166.* system properties. |
317 |
|
System.setSecurityManager(new SecurityManager()); |
318 |
|
} |
319 |
|
for (int i = 0; i < suiteRuns; i++) { |
320 |
< |
TestResult result = junit.textui.TestRunner.run(suite); |
320 |
> |
TestResult result = newPithyTestRunner().doRun(suite); |
321 |
|
if (!result.wasSuccessful()) |
322 |
|
System.exit(1); |
323 |
|
System.gc(); |
554 |
|
public static long LONG_DELAY_MS; |
555 |
|
|
556 |
|
/** |
557 |
< |
* Returns the shortest timed delay. This could |
558 |
< |
* be reimplemented to use for example a Property. |
557 |
> |
* Returns the shortest timed delay. This can be scaled up for |
558 |
> |
* slow machines using the jsr166.delay.factor system property. |
559 |
|
*/ |
560 |
|
protected long getShortDelay() { |
561 |
< |
return 50; |
561 |
> |
return 50 * delayFactor; |
562 |
|
} |
563 |
|
|
564 |
|
/** |
1261 |
|
} finally { |
1262 |
|
if (t.getState() != Thread.State.TERMINATED) { |
1263 |
|
t.interrupt(); |
1264 |
< |
threadFail("Test timed out"); |
1264 |
> |
threadFail("timed out waiting for thread to terminate"); |
1265 |
|
} |
1266 |
|
} |
1267 |
|
} |