public abstract class

ParentRunner

extends Runner
implements Filterable Sortable
java.lang.Object
   ↳ org.junit.runner.Runner
     ↳ org.junit.runners.ParentRunner<T>
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

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, create a composite Description, and run children sequentially.

Summary

Protected Constructors
ParentRunner(Class<?> testClass)
Constructs a new ParentRunner that will run @TestClass
Public Methods
void filter(Filter filter)
Remove tests that don't pass the parameter filter.
Description getDescription()
final TestClass getTestClass()
Returns a TestClass object wrapping the class to be executed.
void run(RunNotifier notifier)
Run the tests for this runner.
void setScheduler(RunnerScheduler scheduler)
Sets a scheduler that determines the order and parallelization of children.
void sort(Sorter sorter)
Sorts the tests using sorter
Protected Methods
Statement childrenInvoker(RunNotifier notifier)
Returns a Statement: Call runChild(Object, RunNotifier) on each object returned by getChildren() (subject to any imposed filter and sort)
Statement classBlock(RunNotifier notifier)
Constructs a Statement to run all of the tests in the test class.
void collectInitializationErrors(List<Throwable> errors)
Adds to errors a throwable for each problem noted with the test class (available from getTestClass()).
abstract Description describeChild(T child)
Returns a Description for child, which can be assumed to be an element of the list returned by getChildren()
abstract List<T> getChildren()
Returns a list of objects that define the children of this Runner.
String getName()
Returns a name used to describe this Runner
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 validatePublicVoidNoArgMethods(Class<? extends Annotation> annotation, boolean isStatic, List<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).
Statement withAfterClasses(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.
Statement withBeforeClasses(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.
[Expand]
Inherited Methods
From class org.junit.runner.Runner
From class java.lang.Object
From interface org.junit.runner.Describable
From interface org.junit.runner.manipulation.Filterable
From interface org.junit.runner.manipulation.Sortable

Protected Constructors

protected ParentRunner (Class<?> testClass)

Constructs a new ParentRunner that will run @TestClass

Public Methods

public void filter (Filter filter)

Remove tests that don't pass the parameter filter.

Parameters
filter the Filter to apply

public Description getDescription ()

public final TestClass getTestClass ()

Returns a TestClass object wrapping the class to be executed.

public void run (RunNotifier notifier)

Run the tests for this runner.

Parameters
notifier will be notified of events while tests are being run--tests being started, finishing, and failing

public void setScheduler (RunnerScheduler scheduler)

Sets a scheduler that determines the order and parallelization of children. Highly experimental feature that may change.

public void sort (Sorter sorter)

Sorts the tests using sorter

Parameters
sorter the Sorter to use for sorting the tests

Protected Methods

protected 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 Statement classBlock (RunNotifier notifier)

Constructs a Statement to run all of the tests in the test class. Override to add pre-/post-processing. Here is an outline of the implementation:

  • Call runChild(Object, RunNotifier) on each object returned by getChildren() (subject to any imposed filter and sort).
  • ALWAYS run all non-overridden @BeforeClass methods on this class and superclasses before the previous step; if any throws an Exception, stop execution and pass the exception on.
  • ALWAYS run all non-overridden @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.

Returns
  • Statement

protected void collectInitializationErrors (List<Throwable> errors)

Adds to 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 abstract Description describeChild (T child)

Returns a Description for child, which can be assumed to be an element of the list returned by getChildren()

protected abstract List<T> getChildren ()

Returns a list of objects that define the children of this Runner.

protected String getName ()

Returns a name used to describe 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(). Subclasses are responsible for making sure that relevant test events are reported through notifier

protected void validatePublicVoidNoArgMethods (Class<? extends Annotation> annotation, boolean isStatic, List<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 Statement withAfterClasses (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 Statement withBeforeClasses (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.