Package org.junit.runners
Class ParentRunner<T>
java.lang.Object
org.junit.runner.Runner
org.junit.runners.ParentRunner<T>
- All Implemented Interfaces:
Describable,Filterable,Orderable,Sortable
- Direct Known Subclasses:
BlockJUnit4ClassRunner,Suite
Provides most of the functionality specific to a Runner that implements a
"parent node" in the test tree, with children defined by objects of some data
type
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,
handle annotated ClassRules, create a composite
Description, and run children sequentially.- Since:
- 4.5
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Lockprivate RunnerSchedulerprivate final TestClassprivate static final List<TestClassValidator> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedParentRunner(Class<?> testClass) Constructs a newParentRunnerthat will run@TestClassprotectedParentRunner(TestClass testClass) Constructs a newParentRunnerthat will run theTestClass. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidapplyValidators(List<Throwable> errors) private booleanprotected StatementchildrenInvoker(RunNotifier notifier) Returns aStatement: CallrunChild(Object, RunNotifier)on each object returned bygetChildren()(subject to any imposed filter and sort)protected StatementclassBlock(RunNotifier notifier) Constructs aStatementto run all of the tests in the test class.protected voidcollectInitializationErrors(List<Throwable> errors) Adds toerrorsa throwable for each problem noted with the test class (available fromgetTestClass()).private Comparator<? super T> comparator(Sorter sorter) protected TestClasscreateTestClass(Class<?> testClass) Deprecated.protected abstract DescriptiondescribeChild(T child) Returns aDescriptionforchild, which can be assumed to be an element of the list returned bygetChildren()voidRemove tests that don't pass the parameterfilter.Returns a list of objects that define the children of this Runner.protected StringgetName()Returns a name used to describe this Runnerprotected Annotation[]final TestClassReturns aTestClassobject wrapping the class to be executed.protected booleanEvaluates whether a child is ignored.voidImplementation ofOrderable.order(Orderer).voidrun(RunNotifier notifier) Run the tests for this runner.protected abstract voidrunChild(T child, RunNotifier notifier) Runs the test corresponding tochild, which can be assumed to be an element of the list returned bygetChildren().private voidrunChildren(RunNotifier notifier) protected final voidrunLeaf(Statement statement, Description description, RunNotifier notifier) Runs aStatementthat represents a leaf (aka atomic) test.voidsetScheduler(RunnerScheduler scheduler) Sets a scheduler that determines the order and parallelization of children.private booleanprivate booleanvoidSorts the tests usingsorterprivate voidvalidate()private voidvalidateClassRules(List<Throwable> errors) protected voidvalidatePublicVoidNoArgMethods(Class<? extends Annotation> annotation, boolean isStatic, List<Throwable> errors) Adds toerrorsif any method in this class is annotated withannotation, but: is not public, or takes parameters, or returns something other than void, or is static (givenisStatic is false), or is not static (givenisStatic is true).protected StatementwithAfterClasses(Statement statement) Returns aStatement: run all non-overridden@AfterClassmethods on this class and superclasses after executingstatement; all AfterClass methods are always executed: exceptions thrown by previous steps are combined, if necessary, with exceptions from AfterClass methods into aMultipleFailureException.protected StatementwithBeforeClasses(Statement statement) Returns aStatement: run all non-overridden@BeforeClassmethods on this class and superclasses before executingstatement; if any throws an Exception, stop execution and pass the exception on.private StatementwithClassRules(Statement statement) protected final StatementwithInterruptIsolation(Statement statement)
-
Field Details
-
VALIDATORS
-
childrenLock
-
testClass
-
filteredChildren
-
scheduler
-
-
Constructor Details
-
ParentRunner
Constructs a newParentRunnerthat will run@TestClass- Throws:
InitializationError
-
ParentRunner
Constructs a newParentRunnerthat will run theTestClass.- Throws:
InitializationError- Since:
- 4.13
-
-
Method Details
-
createTestClass
Deprecated.Please useParentRunner(org.junit.runners.model.TestClass).- Since:
- 4.12
-
getChildren
Returns a list of objects that define the children of this Runner. -
describeChild
Returns aDescriptionforchild, which can be assumed to be an element of the list returned bygetChildren() -
runChild
Runs the test corresponding tochild, which can be assumed to be an element of the list returned bygetChildren(). Subclasses are responsible for making sure that relevant test events are reported throughnotifier -
collectInitializationErrors
Adds toerrorsa throwable for each problem noted with the test class (available fromgetTestClass()). Default implementation adds an error for each method annotated with@BeforeClassor@AfterClassthat is notpublic static voidwith no arguments. -
applyValidators
-
validatePublicVoidNoArgMethods
protected void validatePublicVoidNoArgMethods(Class<? extends Annotation> annotation, boolean isStatic, List<Throwable> errors) Adds toerrorsif any method in this class is annotated withannotation, 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).
-
validateClassRules
-
classBlock
Constructs aStatementto run all of the tests in the test class. Override to add pre-/post-processing. Here is an outline of the implementation:- Determine the children to be run using
getChildren()(subject to any imposed filter and sort). - If there are any children remaining after filtering and ignoring,
construct a statement that will:
- Apply all
ClassRules on the test-class and superclasses. - Run all non-overridden
@BeforeClassmethods on the test-class and superclasses; if any throws an Exception, stop execution and pass the exception on. - Run all remaining tests on the test-class.
- Run all non-overridden
@AfterClassmethods on the test-class and superclasses: exceptions thrown by previous steps are combined, if necessary, with exceptions from AfterClass methods into aMultipleFailureException.
- Apply all
- Returns:
Statement
- Determine the children to be run using
-
areAllChildrenIgnored
private boolean areAllChildrenIgnored() -
withBeforeClasses
Returns aStatement: run all non-overridden@BeforeClassmethods on this class and superclasses before executingstatement; if any throws an Exception, stop execution and pass the exception on. -
withAfterClasses
Returns aStatement: run all non-overridden@AfterClassmethods on this class and superclasses after executingstatement; all AfterClass methods are always executed: exceptions thrown by previous steps are combined, if necessary, with exceptions from AfterClass methods into aMultipleFailureException. -
withClassRules
- Parameters:
statement- the base statement- Returns:
- a RunRules statement if any class-level
Rules are found, or the base statement
-
classRules
- Returns:
- the
ClassRules that can transform the block that runs each method in the tested class.
-
childrenInvoker
Returns aStatement: CallrunChild(Object, RunNotifier)on each object returned bygetChildren()(subject to any imposed filter and sort) -
withInterruptIsolation
- Returns:
- a
Statement: clears interrupt status of current thread after execution of statement
-
isIgnored
Evaluates whether a child is ignored. The default implementation always returnsfalse.BlockJUnit4ClassRunner, for example, overrides this method to filter tests based on theIgnoreannotation. -
runChildren
-
getName
Returns a name used to describe this Runner -
getTestClass
Returns aTestClassobject wrapping the class to be executed. -
runLeaf
Runs aStatementthat represents a leaf (aka atomic) test. -
getRunnerAnnotations
- Returns:
- the annotations that should be attached to this runner's description.
-
getDescription
- Specified by:
getDescriptionin interfaceDescribable- Specified by:
getDescriptionin classRunner- Returns:
- a
Descriptionshowing the tests to be run by the receiver
-
run
Description copied from class:RunnerRun the tests for this runner. -
filter
Description copied from interface:FilterableRemove tests that don't pass the parameterfilter.- Specified by:
filterin interfaceFilterable- Parameters:
filter- theFilterto apply- Throws:
NoTestsRemainException- if all tests are filtered out
-
sort
Description copied from interface:SortableSorts the tests usingsorter -
order
Implementation ofOrderable.order(Orderer).- Specified by:
orderin interfaceOrderable- Throws:
InvalidOrderingException- if orderer does something invalid (like remove or add children)- Since:
- 4.13
-
shouldNotReorder
private boolean shouldNotReorder() -
validate
- Throws:
InitializationError
-
getFilteredChildren
-
shouldRun
-
comparator
-
setScheduler
Sets a scheduler that determines the order and parallelization of children. Highly experimental feature that may change.
-
ParentRunner(org.junit.runners.model.TestClass).