|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.testing.threadtester.BaseThreadedTestRunner
public abstract class BaseThreadedTestRunner
Runs a set of multithreaded tests. This is an abstract base class that defines the basic framework for running tests. Subclasses will add specific mechanisms for defining tests.
To create a multithreaded test, define a class with a public no-arg
constructor, and a set of public instance methods that run the actual test
cases. These methods typically use custom annotations to identify them. To
run the tests, use the runTests(Class, Class...)
method in one of the regular unit test cases. For example, using JUnit 4 syntax:
public class MyClassTest {
public MyClassTest() {}
// This method is invoked as part of the regular unit test
@Test
public void runThreadedTests {
new BaseThreadedTestRunner().runTests(MyClassTest.class, MyClass.class);
}
// This method is invoked by the BaseThreadedTestRunner. It should not be
// invoked as part of the regular unit test.
@SomeTestAnnotation
public void testThreading {
...
}
Note that when a test is run via the BaseThreadedTestRunner, the test targets
will have been instrumented, allowing Breakpoints to be created. For
this reason, the threaded tests cannot be run directly from the test harness,
as the test targets will not have been correctly instrumented. Internally,
the test framework reloads the clases using an instrumenting classloader.
Instrumentation| Constructor Summary | |
|---|---|
BaseThreadedTestRunner()
|
|
| Method Summary | |
|---|---|
protected abstract String |
getWrapperName()
Gets the name of the wrapper class that runs the test. |
boolean |
inThreadedTest()
Returns true when called within a multithreaded test that has been executed via a subclass of this class. |
void |
runTests(Class<?> test,
Class<?>... targets)
Run the multithreaded tests defined in a given class. |
void |
runTests(Class<?> tester,
List<Class<?>> targets)
Run the multithreaded tests defined in a given class. |
void |
setDebug(boolean newDebug)
Sets the debug mode. |
void |
setTimeout(long newTimeout)
Sets the timeout value (in milliseconds) used for all internal waits and joins. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BaseThreadedTestRunner()
| Method Detail |
|---|
public void setDebug(boolean newDebug)
public void setTimeout(long newTimeout)
public boolean inThreadedTest()
public void runTests(Class<?> test,
Class<?>... targets)
A multithreaded test will normally require at least one class to be
instrumented. To specify a single such class, use this method. To specify
multiple classes, use runTests(Class, List).
test - the class containing a set of multithreaded test methods.targets - the classes which should be instrumented.
IllegalArgumentException - if the test class cannot be loaded, or its
test methods cannot be invoked. Will also throw any RuntimeExceptions thrown
by the invoked test methods.Instrumentation,
ClassInstrumentation
public final void runTests(Class<?> tester,
List<Class<?>> targets)
tester - the class containing a set of multithreaded test methods.targets - the classes which should be instrumented.
IllegalArgumentException - if the test class cannot be loaded, or its
test methods cannot be invoked. Will also throw any RuntimeExceptions
thrown by the invoked test methods.Instrumentation,
ClassInstrumentationprotected abstract String getWrapperName()
BaseTestWrapper.
This method is overridden by concrete implementations. An instance of the
wrapper class will be created when runTests(java.lang.Class>, java.lang.Class>...) is invoked, and the
BaseTestWrapper.runTests(java.lang.Class>, java.util.List method will be invoked.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||