|
|
|||||||||
| 上一个类 下一个类 | 框架 无框架 | ||||||||
| 摘要: 嵌套 | 字段 | 构造器 | 方法 | 详细信息: 字段 | 构造器 | 方法 | ||||||||
org.junit.runners Class BlockJUnit4ClassRunner
java.lang.Objectorg.junit.runner.Runner
org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
org.junit.runners.BlockJUnit4ClassRunner
- 所有已实现接口:
- Describable, Filterable, Sortable
- 已知直接子类:
- JUnit4
public class BlockJUnit4ClassRunner
- extends ParentRunner<org.junit.runners.model.FrameworkMethod>
Implements the JUnit 4 standard test case class model, as defined by the
annotations in the org.junit package. Many users will never notice this
class: it is now the default test class runner, but it should have exactly
the same behavior as the old test class runner (JUnit4ClassRunner).
BlockJUnit4ClassRunner has advantages for writers of custom JUnit runners
that are slight changes to the default behavior, however:
- It has a much simpler implementation based on
Statements, allowing new operations to be inserted into the appropriate point in the execution flow. - It is published, and extension and reuse are encouraged, whereas
JUnit4ClassRunnerwas in an internal package, and is now deprecated.
| 构造器摘要 | |
|---|---|
BlockJUnit4ClassRunner(Class<?> klass)
Creates a BlockJUnit4ClassRunner to run klass |
|
| 方法摘要 | |
|---|---|
protected void |
collectInitializationErrors(List<Throwable> errors)
Adds to errors a throwable for each problem noted with the test class (available from ParentRunner.getTestClass()). |
protected List<org.junit.runners.model.FrameworkMethod> |
computeTestMethods()
Returns the methods that run tests. |
protected Object |
createTest()
Returns a new fixture for running a test. |
protected Description |
describeChild(org.junit.runners.model.FrameworkMethod method)
Returns a Description for child, which can be assumed to
be an element of the list returned by ParentRunner.getChildren() |
protected List<org.junit.runners.model.FrameworkMethod> |
getChildren()
Returns a list of objects that define the children of this Runner. |
protected org.junit.runners.model.Statement |
methodBlock(org.junit.runners.model.FrameworkMethod method)
Returns a Statement that, when executed, either returns normally if method passes, or throws an exception if method fails. |
protected org.junit.runners.model.Statement |
methodInvoker(org.junit.runners.model.FrameworkMethod method,
Object test)
Returns a Statement that invokes method on test |
protected org.junit.runners.model.Statement |
possiblyExpectingExceptions(org.junit.runners.model.FrameworkMethod method,
Object test,
org.junit.runners.model.Statement next)
Deprecated. Will be private soon: use Rules instead |
protected List<org.junit.rules.MethodRule> |
rules(Object test)
|
protected void |
runChild(org.junit.runners.model.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 String |
testName(org.junit.runners.model.FrameworkMethod method)
Returns the name that describes method for Descriptions. |
protected void |
validateConstructor(List<Throwable> errors)
Adds to errors if the test class has more than one constructor,
or if the constructor takes parameters. |
protected void |
validateInstanceMethods(List<Throwable> errors)
Deprecated. unused API, will go away in future version |
protected void |
validateOnlyOneConstructor(List<Throwable> errors)
Adds to errors if the test class has more than one constructor
(do not override) |
protected void |
validateTestMethods(List<Throwable> errors)
Adds to errors for each method annotated with @Testthat
is not a public, void instance method with no arguments. |
protected void |
validateZeroArgConstructor(List<Throwable> errors)
Adds to errors if the test class's single constructor
takes parameters
(do not override) |
protected org.junit.runners.model.Statement |
withAfters(org.junit.runners.model.FrameworkMethod method,
Object target,
org.junit.runners.model.Statement statement)
Deprecated. Will be private soon: use Rules instead |
protected org.junit.runners.model.Statement |
withBefores(org.junit.runners.model.FrameworkMethod method,
Object target,
org.junit.runners.model.Statement statement)
Deprecated. Will be private soon: use Rules instead |
protected org.junit.runners.model.Statement |
withPotentialTimeout(org.junit.runners.model.FrameworkMethod method,
Object test,
org.junit.runners.model.Statement next)
Deprecated. Will be private soon: use Rules instead |
| 类方法继承: org.junit.runners.ParentRunner |
|---|
childrenInvoker, classBlock, filter, getDescription, getName, getTestClass, run, setScheduler, sort, validatePublicVoidNoArgMethods, withAfterClasses, withBeforeClasses |
| 类方法继承: org.junit.runner.Runner |
|---|
testCount |
| 类方法继承: java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 构造器详细信息 |
|---|
BlockJUnit4ClassRunner
public BlockJUnit4ClassRunner(Class<?> klass) throws org.junit.runners.model.InitializationError
- Creates a BlockJUnit4ClassRunner to run
klass- 抛出异常:
org.junit.runners.model.InitializationError- if the test class is malformed.
| 方法详细信息 |
|---|
runChild
protected void runChild(org.junit.runners.model.FrameworkMethod method,
RunNotifier notifier)
- Description copied from class:
ParentRunner - Runs the test corresponding to
child, which can be assumed to be an element of the list returned byParentRunner.getChildren(). Subclasses are responsible for making sure that relevant test events are reported throughnotifier - 规范说明:
runChildin classParentRunner<org.junit.runners.model.FrameworkMethod>
describeChild
protected Description describeChild(org.junit.runners.model.FrameworkMethod method)
- Description copied from class:
ParentRunner - Returns a
Descriptionforchild, which can be assumed to be an element of the list returned byParentRunner.getChildren() - 规范说明:
describeChildin classParentRunner<org.junit.runners.model.FrameworkMethod>
getChildren
protected List<org.junit.runners.model.FrameworkMethod> getChildren()
- Description copied from class:
ParentRunner - Returns a list of objects that define the children of this Runner.
- 规范说明:
getChildrenin classParentRunner<org.junit.runners.model.FrameworkMethod>
computeTestMethods
protected List<org.junit.runners.model.FrameworkMethod> computeTestMethods()
- Returns the methods that run tests. Default implementation
returns all methods annotated with
@Teston this class and superclasses that are not overridden.
collectInitializationErrors
protected void collectInitializationErrors(List<Throwable> errors)
- Description copied from class:
ParentRunner - Adds to
errorsa throwable for each problem noted with the test class (available fromParentRunner.getTestClass()). Default implementation adds an error for each method annotated with@BeforeClassor@AfterClassthat is notpublic static voidwith no arguments. - 重写:
collectInitializationErrorsin classParentRunner<org.junit.runners.model.FrameworkMethod>
validateConstructor
protected void validateConstructor(List<Throwable> errors)
- Adds to
errorsif the test class has more than one constructor, or if the constructor takes parameters. Override if a subclass requires different validation rules.
validateOnlyOneConstructor
protected void validateOnlyOneConstructor(List<Throwable> errors)
- Adds to
errorsif the test class has more than one constructor (do not override)
validateZeroArgConstructor
protected void validateZeroArgConstructor(List<Throwable> errors)
- Adds to
errorsif the test class's single constructor takes parameters (do not override)
validateInstanceMethods
@Deprecated protected void validateInstanceMethods(List<Throwable> errors)
- Deprecated. unused API, will go away in future version
- Adds to
errorsfor each method annotated with@Test,@Before, or@Afterthat is not a public, void instance method with no arguments.
validateTestMethods
protected void validateTestMethods(List<Throwable> errors)
- Adds to
errorsfor each method annotated with@Testthat is not a public, void instance method with no arguments.
createTest
protected Object createTest() throws Exception
- Returns a new fixture for running a test. Default implementation executes
the test class's no-argument constructor (validation should have ensured
one exists).
- 抛出异常:
Exception
testName
protected String testName(org.junit.runners.model.FrameworkMethod method)
- Returns the name that describes
methodforDescriptions. Default implementation is the method's name
methodBlock
protected org.junit.runners.model.Statement methodBlock(org.junit.runners.model.FrameworkMethod method)
- Returns a Statement that, when executed, either returns normally if
methodpasses, or throws an exception ifmethodfails. Here is an outline of the default implementation:- Invoke
methodon the result ofcreateTest(), and throw any exceptions thrown by either operation. - HOWEVER, if
method's@Testannotation has theexpectingattribute, return normally only if the previous step threw an exception of the correct type, and throw an exception otherwise. - HOWEVER, if
method's@Testannotation has thetimeoutattribute, throw an exception if the previous step takes more than the specified number of milliseconds. - ALWAYS allow
@Rulefields to modify the execution of the above steps. ARulemay prevent all execution of the above steps, or add additional behavior before and after, or modify thrown exceptions. For more information, seeMethodRule - ALWAYS run all non-overridden
@Beforemethods on this class and superclasses before any of the previous steps; if any throws an Exception, stop execution and pass the exception on. - ALWAYS run all non-overridden
@Aftermethods 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 aMultipleFailureException.
- Invoke
methodInvoker
protected org.junit.runners.model.Statement methodInvoker(org.junit.runners.model.FrameworkMethod method,
Object test)
- Returns a
Statementthat invokesmethodontest
possiblyExpectingExceptions
@Deprecated protected org.junit.runners.model.Statement possiblyExpectingExceptions(org.junit.runners.model.FrameworkMethod method, Object test, org.junit.runners.model.Statement next)
- Deprecated. Will be private soon: use Rules instead
- Returns a
Statement: ifmethod's@Testannotation has theexpectingattribute, return normally only ifnextthrows an exception of the correct type, and throw an exception otherwise.
withPotentialTimeout
@Deprecated protected org.junit.runners.model.Statement withPotentialTimeout(org.junit.runners.model.FrameworkMethod method, Object test, org.junit.runners.model.Statement next)
- Deprecated. Will be private soon: use Rules instead
- Returns a
Statement: ifmethod's@Testannotation has thetimeoutattribute, throw an exception ifnexttakes more than the specified number of milliseconds.
withBefores
@Deprecated protected org.junit.runners.model.Statement withBefores(org.junit.runners.model.FrameworkMethod method, Object target, org.junit.runners.model.Statement statement)
- Deprecated. Will be private soon: use Rules instead
- Returns a
Statement: run all non-overridden@Beforemethods on this class and superclasses before runningnext; if any throws an Exception, stop execution and pass the exception on.
withAfters
@Deprecated protected org.junit.runners.model.Statement withAfters(org.junit.runners.model.FrameworkMethod method, Object target, org.junit.runners.model.Statement statement)
- Deprecated. Will be private soon: use Rules instead
- Returns a
Statement: run all non-overridden@Aftermethods on this class and superclasses before runningnext; all After methods are always executed: exceptions thrown by previous steps are combined, if necessary, with exceptions from After methods into aMultipleFailureException.
rules
protected List<org.junit.rules.MethodRule> rules(Object test)
- 返回:
- the MethodRules that can transform the block that runs each method in the tested class.
|
|
|||||||||
| 上一个类 下一个类 | 框架 无框架 | ||||||||
| 摘要: 嵌套 | 字段 | 构造器 | 方法 | 详细信息: 字段 | 构造器 | 方法 | ||||||||
