org.junit.runners
public abstract class ParentRunner<T> extends Runner implements Filterable, Sortable
T. (For BlockJUnit4ClassRunner, T is
Method . For Suite, T is Class.) Subclasses
must implement finding the children of the node, describing each child, and
running each child. ParentRunner will filter and sort children, handle
@BeforeClass and @AfterClass methods, create a composite
Description, and run children sequentially.| Modifier | Constructor and Description |
|---|---|
protected |
ParentRunner(java.lang.Class<?> testClass)
Constructs a new
ParentRunner that will run @TestClass |
| Modifier and Type | Method and Description |
|---|---|
protected org.junit.runners.model.Statement |
childrenInvoker(RunNotifier notifier)
Returns a
Statement: Call runChild(Object, RunNotifier)
on each object returned by getChildren() (subject to any imposed
filter and sort) |
protected org.junit.runners.model.Statement |
classBlock(RunNotifier notifier)
Constructs a
Statement to run all of the tests in the test class. |
protected void |
collectInitializationErrors(java.util.List<java.lang.Throwable> errors)
Adds to
errors a throwable for each problem noted with the test class (available from getTestClass()). |
protected abstract Description |
describeChild(T child)
Returns a
Description for child, which can be assumed to
be an element of the list returned by getChildren() |
void |
filter(Filter filter)
Remove tests that don't pass the parameter
filter. |
protected abstract java.util.List<T> |
getChildren()
Returns a list of objects that define the children of this Runner.
|
Description |
getDescription() |
protected java.lang.String |
getName()
Returns a name used to describe this Runner
|
protected org.junit.runners.model.TestClass |
getTestClass()
Returns a
TestClass object wrapping the class to be executed. |
void |
run(RunNotifier notifier)
Run the tests for this runner.
|
protected abstract void |
runChild(T child,
RunNotifier notifier)
Runs the test corresponding to
child, which can be assumed to be
an element of the list returned by getChildren(). |
void |
sort(Sorter sorter)
Sorts the tests using
sorter |
protected void |
validatePublicVoidNoArgMethods(java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
boolean isStatic,
java.util.List<java.lang.Throwable> errors)
Adds to
errors if any method in this class is annotated with
annotation, but:
is not public, or
takes parameters, or
returns something other than void, or
is static (given isStatic is false), or
is not static (given isStatic is true). |
protected org.junit.runners.model.Statement |
withAfterClasses(org.junit.runners.model.Statement statement)
Returns a
Statement: run all non-overridden @AfterClass methods on this class
and superclasses before executing statement; all AfterClass methods are
always executed: exceptions thrown by previous steps are combined, if
necessary, with exceptions from AfterClass methods into a
MultipleFailureException. |
protected org.junit.runners.model.Statement |
withBeforeClasses(org.junit.runners.model.Statement statement)
Returns a
Statement: run all non-overridden @BeforeClass methods on this class
and superclasses before executing statement; if any throws an
Exception, stop execution and pass the exception on. |
protected ParentRunner(java.lang.Class<?> testClass)
throws org.junit.runners.model.InitializationError
ParentRunner that will run @TestClassorg.junit.runners.model.InitializationErrorprotected abstract java.util.List<T> getChildren()
protected abstract Description describeChild(T child)
Description for child, which can be assumed to
be an element of the list returned by getChildren()protected abstract void runChild(T child, RunNotifier notifier)
child, which can be assumed to be
an element of the list returned by getChildren().
Subclasses are responsible for making sure that relevant test events are
reported through notifierprotected void collectInitializationErrors(java.util.List<java.lang.Throwable> errors)
errors a throwable for each problem noted with the test class (available from getTestClass()).
Default implementation adds an error for each method annotated with
@BeforeClass or @AfterClass that is not
public static void with no arguments.protected void validatePublicVoidNoArgMethods(java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
boolean isStatic,
java.util.List<java.lang.Throwable> errors)
errors if any method in this class is annotated with
annotation, but:
isStatic is false), or
isStatic is true).protected org.junit.runners.model.Statement classBlock(RunNotifier notifier)
Statement to run all of the tests in the test class. Override to add pre-/post-processing.
Here is an outline of the implementation:
runChild(Object, RunNotifier) on each object returned by getChildren() (subject to any imposed filter and sort).@BeforeClass methods on this class
and superclasses before the previous step; if any throws an
Exception, stop execution and pass the exception on.
@AfterClass methods on this class
and superclasses before any of the previous steps; all AfterClass methods are
always executed: exceptions thrown by previous steps are combined, if
necessary, with exceptions from AfterClass methods into a
MultipleFailureException.
notifier - Statementprotected org.junit.runners.model.Statement withBeforeClasses(org.junit.runners.model.Statement statement)
Statement: run all non-overridden @BeforeClass methods on this class
and superclasses before executing statement; if any throws an
Exception, stop execution and pass the exception on.protected org.junit.runners.model.Statement withAfterClasses(org.junit.runners.model.Statement statement)
Statement: run all non-overridden @AfterClass methods on this class
and superclasses before executing statement; all AfterClass methods are
always executed: exceptions thrown by previous steps are combined, if
necessary, with exceptions from AfterClass methods into a
MultipleFailureException.protected org.junit.runners.model.Statement childrenInvoker(RunNotifier notifier)
Statement: Call runChild(Object, RunNotifier)
on each object returned by getChildren() (subject to any imposed
filter and sort)protected java.lang.String getName()
protected final org.junit.runners.model.TestClass getTestClass()
TestClass object wrapping the class to be executed.public Description getDescription()
getDescription in interface DescribablegetDescription in class RunnerDescription showing the tests to be run by the receiverpublic void run(RunNotifier notifier)
Runnerpublic void filter(Filter filter) throws NoTestsRemainException
Filterablefilter.filter in interface Filterablefilter - the Filter to applyNoTestsRemainException - if all tests are filtered out