public class BlockJUnit4ClassRunner extends ParentRunner<FrameworkMethod>
JUnit4ClassRunner).
BlockJUnit4ClassRunner has advantages for writers of custom JUnit runners that are slight changes to the default behavior, however:
Statements,
allowing new operations to be inserted into the appropriate point in the
execution flow.
JUnit4ClassRunner was in an internal package, and is now deprecated.
In turn, in 2009 we introduced Rules. In many cases where extending
BlockJUnit4ClassRunner was necessary to add new behavior, Rules can
be used, which makes the extension more reusable and composable.
| Constructor and Description |
|---|
BlockJUnit4ClassRunner(java.lang.Class<?> klass)
Creates a BlockJUnit4ClassRunner to run
klass |
| Modifier and Type | Method and Description |
|---|---|
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 ParentRunner.getTestClass()). |
protected java.util.List<FrameworkMethod> |
computeTestMethods()
Returns the methods that run tests.
|
protected java.lang.Object |
createTest()
Returns a new fixture for running a test.
|
protected Description |
describeChild(FrameworkMethod method)
Returns a
Description for child, which can be assumed to
be an element of the list returned by ParentRunner.getChildren() |
protected java.util.List<FrameworkMethod> |
getChildren()
Returns a list of objects that define the children of this Runner.
|
protected java.util.List<TestRule> |
getTestRules(java.lang.Object target) |
protected boolean |
isIgnored(FrameworkMethod child)
Evaluates whether
FrameworkMethods are ignored based on the
Ignore annotation. |
protected Statement |
methodBlock(FrameworkMethod method)
Returns a Statement that, when executed, either returns normally if
method passes, or throws an exception if method fails. |
protected Statement |
methodInvoker(FrameworkMethod method,
java.lang.Object test)
|
protected Statement |
possiblyExpectingExceptions(FrameworkMethod method,
java.lang.Object test,
Statement next)
Returns a
Statement: if method's @Test annotation
has the expecting attribute, return normally only if next
throws an exception of the correct type, and throw an exception
otherwise. |
protected java.util.List<MethodRule> |
rules(java.lang.Object target) |
protected void |
runChild(FrameworkMethod method,
RunNotifier notifier)
Runs the test corresponding to
child, which can be assumed to be
an element of the list returned by ParentRunner.getChildren(). |
protected java.lang.String |
testName(FrameworkMethod method)
Returns the name that describes
method for Descriptions. |
protected void |
validateConstructor(java.util.List<java.lang.Throwable> errors)
Adds to
errors if the test class has more than one constructor,
or if the constructor takes parameters. |
protected void |
validateFields(java.util.List<java.lang.Throwable> errors) |
protected void |
validateInstanceMethods(java.util.List<java.lang.Throwable> errors)
Deprecated.
|
protected void |
validateNoNonStaticInnerClass(java.util.List<java.lang.Throwable> errors) |
protected void |
validateOnlyOneConstructor(java.util.List<java.lang.Throwable> errors)
Adds to
errors if the test class has more than one constructor
(do not override) |
protected void |
validateTestMethods(java.util.List<java.lang.Throwable> errors)
Adds to
errors for each method annotated with @Testthat
is not a public, void instance method with no arguments. |
protected void |
validateZeroArgConstructor(java.util.List<java.lang.Throwable> errors)
Adds to
errors if the test class's single constructor takes
parameters (do not override) |
protected Statement |
withAfters(FrameworkMethod method,
java.lang.Object target,
Statement statement)
Returns a
Statement: run all non-overridden @After
methods on this class and superclasses before running next; all
After methods are always executed: exceptions thrown by previous steps
are combined, if necessary, with exceptions from After methods into a
MultipleFailureException. |
protected Statement |
withBefores(FrameworkMethod method,
java.lang.Object target,
Statement statement)
Returns a
Statement: run all non-overridden @Before
methods on this class and superclasses before running next; if
any throws an Exception, stop execution and pass the exception on. |
protected Statement |
withPotentialTimeout(FrameworkMethod method,
java.lang.Object test,
Statement next)
Deprecated.
|
childrenInvoker, classBlock, classRules, createTestClass, filter, getDescription, getName, getRunnerAnnotations, getTestClass, run, runLeaf, setScheduler, sort, validatePublicVoidNoArgMethods, withAfterClasses, withBeforeClassespublic BlockJUnit4ClassRunner(java.lang.Class<?> klass)
throws InitializationError
klassInitializationError - if the test class is malformed.protected void runChild(FrameworkMethod method, RunNotifier notifier)
ParentRunnerchild, which can be assumed to be
an element of the list returned by ParentRunner.getChildren().
Subclasses are responsible for making sure that relevant test events are
reported through notifierrunChild in class ParentRunner<FrameworkMethod>protected boolean isIgnored(FrameworkMethod child)
FrameworkMethods are ignored based on the
Ignore annotation.isIgnored in class ParentRunner<FrameworkMethod>protected Description describeChild(FrameworkMethod method)
ParentRunnerDescription for child, which can be assumed to
be an element of the list returned by ParentRunner.getChildren()describeChild in class ParentRunner<FrameworkMethod>protected java.util.List<FrameworkMethod> getChildren()
ParentRunnergetChildren in class ParentRunner<FrameworkMethod>protected java.util.List<FrameworkMethod> computeTestMethods()
@Test on this class and superclasses that
are not overridden.protected void collectInitializationErrors(java.util.List<java.lang.Throwable> errors)
ParentRunnererrors a throwable for each problem noted with the test class (available from ParentRunner.getTestClass()).
Default implementation adds an error for each method annotated with
@BeforeClass or @AfterClass that is not
public static void with no arguments.collectInitializationErrors in class ParentRunner<FrameworkMethod>protected void validateNoNonStaticInnerClass(java.util.List<java.lang.Throwable> errors)
protected void validateConstructor(java.util.List<java.lang.Throwable> errors)
errors if the test class has more than one constructor,
or if the constructor takes parameters. Override if a subclass requires
different validation rules.protected void validateOnlyOneConstructor(java.util.List<java.lang.Throwable> errors)
errors if the test class has more than one constructor
(do not override)protected void validateZeroArgConstructor(java.util.List<java.lang.Throwable> errors)
errors if the test class's single constructor takes
parameters (do not override)@Deprecated protected void validateInstanceMethods(java.util.List<java.lang.Throwable> errors)
errors for each method annotated with @Test,
@Before, or @After that is not a public, void instance
method with no arguments.protected void validateFields(java.util.List<java.lang.Throwable> errors)
protected void validateTestMethods(java.util.List<java.lang.Throwable> errors)
errors for each method annotated with @Testthat
is not a public, void instance method with no arguments.protected java.lang.Object createTest()
throws java.lang.Exception
java.lang.Exceptionprotected java.lang.String testName(FrameworkMethod method)
method for Descriptions.
Default implementation is the method's nameprotected Statement methodBlock(FrameworkMethod method)
method passes, or throws an exception if method fails.
Here is an outline of the default implementation:
method on the result of createTest(), and
throw any exceptions thrown by either operation.
method's @Test annotation has the expecting attribute, return normally only if the previous step threw an
exception of the correct type, and throw an exception otherwise.
method's @Test annotation has the timeout attribute, throw an exception if the previous step takes more
than the specified number of milliseconds.
@Before methods on this class
and superclasses before any of the previous steps; if any throws an
Exception, stop execution and pass the exception on.
@After methods on this class
and superclasses after any of the previous steps; all After methods are
always executed: exceptions thrown by previous steps are combined, if
necessary, with exceptions from After methods into a
MultipleFailureException.
@Rule fields to modify the execution of the
above steps. A Rule may prevent all execution of the above steps,
or add additional behavior before and after, or modify thrown exceptions.
For more information, see TestRule
protected Statement methodInvoker(FrameworkMethod method, java.lang.Object test)
protected Statement possiblyExpectingExceptions(FrameworkMethod method, java.lang.Object test, Statement next)
Statement: if method's @Test annotation
has the expecting attribute, return normally only if next
throws an exception of the correct type, and throw an exception
otherwise.@Deprecated protected Statement withPotentialTimeout(FrameworkMethod method, java.lang.Object test, Statement next)
Statement: if method's @Test annotation
has the timeout attribute, throw an exception if next
takes more than the specified number of milliseconds.protected Statement withBefores(FrameworkMethod method, java.lang.Object target, Statement statement)
Statement: run all non-overridden @Before
methods on this class and superclasses before running next; if
any throws an Exception, stop execution and pass the exception on.protected Statement withAfters(FrameworkMethod method, java.lang.Object target, Statement statement)
Statement: run all non-overridden @After
methods on this class and superclasses before running next; all
After methods are always executed: exceptions thrown by previous steps
are combined, if necessary, with exceptions from After methods into a
MultipleFailureException.protected java.util.List<MethodRule> rules(java.lang.Object target)
target - the test case instanceprotected java.util.List<TestRule> getTestRules(java.lang.Object target)
target - the test case instance