public abstract class RunnerBuilder
extends java.lang.Object
RunnerBuilders. A custom runner class with a constructor taking
a RunnerBuilder parameter will be passed the instance of RunnerBuilder used to build that runner itself.
For example,
imagine a custom runner that builds suites based on a list of classes in a text file:
\@RunWith(TextFileSuite.class)
\@SuiteSpecFile("mysuite.txt")
class MySuite {}
The implementation of TextFileSuite might include:
public TextFileSuite(Class testClass, RunnerBuilder builder) {
// ...
for (String className : readClassNames())
addRunner(builder.runnerForClass(Class.forName(className)));
// ...
}
Suite| Modifier and Type | Field and Description |
|---|---|
private java.util.Set<java.lang.Class<?>> |
parents |
| Constructor and Description |
|---|
RunnerBuilder() |
| Modifier and Type | Method and Description |
|---|---|
(package private) java.lang.Class<?> |
addParent(java.lang.Class<?> parent) |
private void |
configureRunner(Runner runner) |
(package private) void |
removeParent(java.lang.Class<?> klass) |
abstract Runner |
runnerForClass(java.lang.Class<?> testClass)
Override to calculate the correct runner for a test class at runtime.
|
private java.util.List<Runner> |
runners(java.lang.Class<?>[] children) |
java.util.List<Runner> |
runners(java.lang.Class<?> parent,
java.lang.Class<?>[] children)
Constructs and returns a list of Runners, one for each child class in
children. |
java.util.List<Runner> |
runners(java.lang.Class<?> parent,
java.util.List<java.lang.Class<?>> children) |
Runner |
safeRunnerForClass(java.lang.Class<?> testClass)
Always returns a runner for the given test class.
|
public abstract Runner runnerForClass(java.lang.Class<?> testClass) throws java.lang.Throwable
testClass - class to be runjava.lang.Throwable - if a runner cannot be constructedpublic Runner safeRunnerForClass(java.lang.Class<?> testClass)
In case of an exception a runner will be returned that prints an error instead of running tests.
Note that some of the internal JUnit implementations of RunnerBuilder will return
null from this method, but no RunnerBuilder passed to a Runner constructor will
return null from this method.
testClass - class to be runprivate void configureRunner(Runner runner) throws InvalidOrderingException
InvalidOrderingExceptionjava.lang.Class<?> addParent(java.lang.Class<?> parent)
throws InitializationError
InitializationErrorvoid removeParent(java.lang.Class<?> klass)
public java.util.List<Runner> runners(java.lang.Class<?> parent, java.lang.Class<?>[] children) throws InitializationError
children. Care is taken to avoid infinite recursion:
this builder will throw an exception if it is requested for another
runner for parent before this call completes.InitializationErrorpublic java.util.List<Runner> runners(java.lang.Class<?> parent, java.util.List<java.lang.Class<?>> children) throws InitializationError
InitializationErrorprivate java.util.List<Runner> runners(java.lang.Class<?>[] children)