net.sourceforge.groboutils.junit.v1
Class MultiThreadedTestRunner

java.lang.Object
  extended bynet.sourceforge.groboutils.junit.v1.MultiThreadedTestRunner

public class MultiThreadedTestRunner
extends java.lang.Object

A framework which allows for an array of tests to be run asynchronously. TestCases should reference this class in a test method.

Update for July 9, 2003: now, you can also register TestRunner instances as monitors (request 771008); these run parallel with the standard TestRunner instances, but they only quit when all of the standard TestRunner instances end.

Fixed bugs 771000 and 771001: spawned threads are now Daemon threads, and all "wild threads" (threads that just won't stop) are Thread.stop()ed.

All these changes have made this class rather fragile, as there are many threaded timing issues to deal with. Expect future refactoring with backwards compatibility.

Since:
Jan 14, 2002
Version:
$Date: 2003/10/03 14:26:45 $
Author:
Matt Albrecht groboclown@users.sourceforge.net

Nested Class Summary
static class MultiThreadedTestRunner.TestDeathException
          An exception that declares that the test has been stop()ed.
 
Constructor Summary
MultiThreadedTestRunner(TestRunnable[] tr)
          Create a new utility instance with the given set of parallel runners.
MultiThreadedTestRunner(TestRunnable[] runners, TestRunnable[] monitors)
          Create a new utility instance with the given set of parallel runners and a set of monitors.
 
Method Summary
 void runTestRunnables()
          Run each test given in a separate thread.
 void runTestRunnables(long maxTime)
          Runs each test given in a separate thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiThreadedTestRunner

public MultiThreadedTestRunner(TestRunnable[] tr)
Create a new utility instance with the given set of parallel runners. All runners passed into this method must end on their own, else it's an error.


MultiThreadedTestRunner

public MultiThreadedTestRunner(TestRunnable[] runners,
                               TestRunnable[] monitors)
Create a new utility instance with the given set of parallel runners and a set of monitors. The runners must end on their own, but the monitors can run until told to stop.

Parameters:
runners - a non-null, non-empty collection of test runners.
monitors - a list of monitor runners, which may be null or empty.
Method Detail

runTestRunnables

public void runTestRunnables()
                      throws java.lang.Throwable
Run each test given in a separate thread. Wait for each thread to finish running, then return.

As of July 9, 2003, this method will not wait forever, but rather will wait for the internal maximum run time, which is by default 24 hours; for most unit testing scenarios, this is more than sufficient.

Throws:
java.lang.Throwable - thrown on a test run if a threaded task throws an exception.

runTestRunnables

public void runTestRunnables(long maxTime)
                      throws java.lang.Throwable
Runs each test given in a separate thread. Waits for each thread to finish running (possibly killing them), then returns.

Parameters:
maxTime - the maximum amount of milliseconds to wait for the tests to run. If the time is <= 0, then the tests will run until they are complete. Otherwise, any threads that don't complete by the given number of milliseconds will be killed, and a failure will be thrown.
Throws:
java.lang.Throwable - thrown from the underlying tests if they happen to cause an error.


Copyright © 2001-2003 by The GroboUtils Project