Package org.junit.runners.model
Class RunnerBuilder
java.lang.Object
org.junit.runners.model.RunnerBuilder
- Direct Known Subclasses:
AllDefaultPossibilitiesBuilder
,AnnotatedBuilder
,IgnoredBuilder
,JUnit3Builder
,JUnit4Builder
,NullBuilder
,SuiteMethodBuilder
A RunnerBuilder is a strategy for constructing runners for classes.
Only writers of custom runners should use
RunnerBuilder
s. 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))); // ... }
- Since:
- 4.5
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) Class
<?> private void
configureRunner
(Runner runner) (package private) void
removeParent
(Class<?> klass) abstract Runner
runnerForClass
(Class<?> testClass) Override to calculate the correct runner for a test class at runtime.Constructs and returns a list of Runners, one for each child class inchildren
.safeRunnerForClass
(Class<?> testClass) Always returns a runner for the given test class.
-
Field Details
-
parents
-
-
Constructor Details
-
RunnerBuilder
public RunnerBuilder()
-
-
Method Details
-
runnerForClass
Override to calculate the correct runner for a test class at runtime.- Parameters:
testClass
- class to be run- Returns:
- a Runner
- Throws:
Throwable
- if a runner cannot be constructed
-
safeRunnerForClass
Always returns a runner for the given test class.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 returnnull
from this method.- Parameters:
testClass
- class to be run- Returns:
- a Runner
-
configureRunner
- Throws:
InvalidOrderingException
-
addParent
- Throws:
InitializationError
-
removeParent
-
runners
Constructs and returns a list of Runners, one for each child class inchildren
. Care is taken to avoid infinite recursion: this builder will throw an exception if it is requested for another runner forparent
before this call completes.- Throws:
InitializationError
-
runners
- Throws:
InitializationError
-
runners
-