类 JUnit4ClassRunner
- 所有已实现的接口:
org.junit.runner.Describable,org.junit.runner.manipulation.Filterable,org.junit.runner.manipulation.Orderable,org.junit.runner.manipulation.Sortable
- 直接已知子类:
InfraRunner
JUnit4ClassRunner is a custom extension of JUnit's
BlockJUnit4ClassRunner which provides functionality of the
TestContext Framework to standard JUnit tests by means of the
TestContextManager and associated support classes and annotations.
To use this class, simply annotate a JUnit 4 based test class with
@RunWith(JUnit4ClassRunner.class) or @RunWith(Runner.class).
The following list constitutes all annotations currently supported directly
or indirectly by JUnit4ClassRunner. (Note that additional
annotations may be supported by various
TestExecutionListener
or TestContextBootstrapper
implementations.)
@Test(expected=...)@Test(timeout=...)@Timed@Repeat@Ignore@ProfileValueSourceConfiguration@IfProfileValue
If you would like to use the TestContext Framework with a runner
other than this one, use InfraClassRule and InfraMethodRule.
NOTE: this class requires JUnit 4.12 or higher.
- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen, Juergen Hoeller
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明private static final cn.taketoday.logging.Loggerprivate final TestContextManagerprivate static final Method -
构造器概要
构造器构造器说明JUnit4ClassRunner(Class<?> clazz) Construct a newJUnit4ClassRunnerand initialize aTestContextManagerto provide Infra testing functionality to standard JUnit tests. -
方法概要
修饰符和类型方法说明protected ObjectDelegate to the parent implementation for creating the test instance and then allow theTestContextManagerto prepare the test instance before returning it.protected TestContextManagercreateTestContextManager(Class<?> clazz) Create a newTestContextManagerfor the supplied test class.private static voidensureInfraRulesAreNotPresent(Class<?> testClass) org.junit.runner.DescriptionReturn a description suitable for an ignored test class if the test is disabled via@IfProfileValueat the class-level, and otherwise delegate to the parent implementation.getExpectedException(org.junit.runners.model.FrameworkMethod frameworkMethod) Get theexceptionthat the supplied test method is expected to throw.protected longgetInfraTimeout(org.junit.runners.model.FrameworkMethod frameworkMethod) Retrieve the configured Infra-specifictimeoutfrom the@Timedannotation on the supplied test method.protected longgetJUnitTimeout(org.junit.runners.model.FrameworkMethod frameworkMethod) Retrieve the configured JUnittimeoutfrom the@Testannotation on the supplied test method.protected final TestContextManagerGet theTestContextManagerassociated with this runner.protected booleanisTestMethodIgnored(org.junit.runners.model.FrameworkMethod frameworkMethod) Returntrueif@Ignoreis present for the supplied test method or if the test method is disabled via@IfProfileValue.protected org.junit.runners.model.StatementmethodBlock(org.junit.runners.model.FrameworkMethod frameworkMethod) Augment the default JUnit behavior with potential repeats of the entire execution chain.protected org.junit.runners.model.StatementpossiblyExpectingExceptions(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement next) Perform the same logic asBlockJUnit4ClassRunner.possiblyExpectingExceptions(FrameworkMethod, Object, Statement)except that the expected exception is retrieved usinggetExpectedException(FrameworkMethod).voidrun(org.junit.runner.notification.RunNotifier notifier) Check whether the test is enabled in the current execution environment.protected voidrunChild(org.junit.runners.model.FrameworkMethod frameworkMethod, org.junit.runner.notification.RunNotifier notifier) Perform the same logic asBlockJUnit4ClassRunner.runChild(FrameworkMethod, RunNotifier), except that tests are determined to be ignored byisTestMethodIgnored(FrameworkMethod).protected org.junit.runners.model.StatementwithAfterClasses(org.junit.runners.model.Statement statement) Wrap theStatementreturned by the parent implementation with aRunAfterTestClassCallbacksstatement, thus preserving the default JUnit functionality while adding support for the TestContext Framework.protected org.junit.runners.model.StatementwithAfters(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement statement) Wrap theStatementreturned by the parent implementation with aRunAfterTestMethodCallbacksstatement, thus preserving the default functionality while adding support for the Infra TestContext Framework.protected org.junit.runners.model.StatementwithAfterTestExecutionCallbacks(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement statement) Wrap the suppliedStatementwith aRunAfterTestExecutionCallbacksstatement, thus preserving the default functionality while adding support for the TestContext Framework.protected org.junit.runners.model.StatementwithBeforeClasses(org.junit.runners.model.Statement statement) Wrap theStatementreturned by the parent implementation with aRunBeforeTestClassCallbacksstatement, thus preserving the default JUnit functionality while adding support for the Infra TestContext Framework.protected org.junit.runners.model.StatementwithBefores(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement statement) Wrap theStatementreturned by the parent implementation with aRunBeforeTestMethodCallbacksstatement, thus preserving the default functionality while adding support for the Infra TestContext Framework.protected org.junit.runners.model.StatementwithBeforeTestExecutionCallbacks(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement statement) Wrap the suppliedStatementwith aRunBeforeTestExecutionCallbacksstatement, thus preserving the default functionality while adding support for the TestContext Framework.protected org.junit.runners.model.StatementwithPotentialRepeat(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement next) Wrap the suppliedStatementwith aRepeatTeststatement.protected org.junit.runners.model.StatementwithPotentialTimeout(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement next) Perform the same logic asBlockJUnit4ClassRunner.withPotentialTimeout(FrameworkMethod, Object, Statement)but with additional support for Framework's@Timedannotation.private org.junit.runners.model.StatementwithRulesReflectively(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement statement) Invoke JUnit's privatewithRules()method using reflection.从类继承的方法 org.junit.runners.BlockJUnit4ClassRunner
collectInitializationErrors, computeTestMethods, createTest, describeChild, getChildren, getTestRules, isIgnored, methodInvoker, rules, testName, validateConstructor, validateFields, validateInstanceMethods, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateTestMethods, validateZeroArgConstructor从类继承的方法 org.junit.runners.ParentRunner
childrenInvoker, classBlock, classRules, createTestClass, filter, getName, getRunnerAnnotations, getTestClass, order, runLeaf, setScheduler, sort, validatePublicVoidNoArgMethods, withInterruptIsolation从类继承的方法 org.junit.runner.Runner
testCount
-
字段详细资料
-
logger
private static final cn.taketoday.logging.Logger logger -
withRulesMethod
-
testContextManager
-
-
构造器详细资料
-
JUnit4ClassRunner
Construct a newJUnit4ClassRunnerand initialize aTestContextManagerto provide Infra testing functionality to standard JUnit tests.- 参数:
clazz- the test class to be run- 抛出:
org.junit.runners.model.InitializationError- 另请参阅:
-
-
方法详细资料
-
ensureInfraRulesAreNotPresent
-
createTestContextManager
Create a newTestContextManagerfor the supplied test class.Can be overridden by subclasses.
- 参数:
clazz- the test class to be managed
-
getTestContextManager
Get theTestContextManagerassociated with this runner. -
getDescription
public org.junit.runner.Description getDescription()Return a description suitable for an ignored test class if the test is disabled via@IfProfileValueat the class-level, and otherwise delegate to the parent implementation.- 指定者:
getDescription在接口中org.junit.runner.Describable- 覆盖:
getDescription在类中org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>- 另请参阅:
-
run
public void run(org.junit.runner.notification.RunNotifier notifier) Check whether the test is enabled in the current execution environment.This prevents classes with a non-matching
@IfProfileValueannotation from running altogether, even skipping the execution ofprepareTestInstance()methods inTestExecutionListeners.- 覆盖:
run在类中org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>- 另请参阅:
-
withBeforeClasses
protected org.junit.runners.model.Statement withBeforeClasses(org.junit.runners.model.Statement statement) Wrap theStatementreturned by the parent implementation with aRunBeforeTestClassCallbacksstatement, thus preserving the default JUnit functionality while adding support for the Infra TestContext Framework.- 覆盖:
withBeforeClasses在类中org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>- 另请参阅:
-
withAfterClasses
protected org.junit.runners.model.Statement withAfterClasses(org.junit.runners.model.Statement statement) Wrap theStatementreturned by the parent implementation with aRunAfterTestClassCallbacksstatement, thus preserving the default JUnit functionality while adding support for the TestContext Framework.- 覆盖:
withAfterClasses在类中org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>- 另请参阅:
-
createTest
Delegate to the parent implementation for creating the test instance and then allow theTestContextManagerto prepare the test instance before returning it.- 覆盖:
createTest在类中org.junit.runners.BlockJUnit4ClassRunner- 抛出:
Exception- 另请参阅:
-
runChild
protected void runChild(org.junit.runners.model.FrameworkMethod frameworkMethod, org.junit.runner.notification.RunNotifier notifier) Perform the same logic asBlockJUnit4ClassRunner.runChild(FrameworkMethod, RunNotifier), except that tests are determined to be ignored byisTestMethodIgnored(FrameworkMethod).- 覆盖:
runChild在类中org.junit.runners.BlockJUnit4ClassRunner
-
methodBlock
protected org.junit.runners.model.Statement methodBlock(org.junit.runners.model.FrameworkMethod frameworkMethod) Augment the default JUnit behavior with potential repeats of the entire execution chain.Furthermore, support for timeouts has been moved down the execution chain in order to include execution of
@Beforeand@Aftermethods within the timed execution. Note that this differs from the default JUnit behavior of executing@Beforeand@Aftermethods in the main thread while executing the actual test method in a separate thread. Thus, the net effect is that@Beforeand@Aftermethods will be executed in the same thread as the test method. As a consequence, JUnit-specified timeouts will work fine in combination with Infra transactions. However, JUnit-specific timeouts still differ from Infra-specific timeouts in that the former execute in a separate thread while the latter simply execute in the main thread (like regular tests).- 覆盖:
methodBlock在类中org.junit.runners.BlockJUnit4ClassRunner- 另请参阅:
-
BlockJUnit4ClassRunner.methodInvoker(FrameworkMethod, Object)withBeforeTestExecutionCallbacks(FrameworkMethod, Object, Statement)withAfterTestExecutionCallbacks(FrameworkMethod, Object, Statement)possiblyExpectingExceptions(FrameworkMethod, Object, Statement)withBefores(FrameworkMethod, Object, Statement)withAfters(FrameworkMethod, Object, Statement)withRulesReflectively(FrameworkMethod, Object, Statement)withPotentialRepeat(FrameworkMethod, Object, Statement)withPotentialTimeout(FrameworkMethod, Object, Statement)
-
withRulesReflectively
private org.junit.runners.model.Statement withRulesReflectively(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement statement) Invoke JUnit's privatewithRules()method using reflection. -
isTestMethodIgnored
protected boolean isTestMethodIgnored(org.junit.runners.model.FrameworkMethod frameworkMethod) Returntrueif@Ignoreis present for the supplied test method or if the test method is disabled via@IfProfileValue. -
possiblyExpectingExceptions
protected org.junit.runners.model.Statement possiblyExpectingExceptions(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement next) Perform the same logic asBlockJUnit4ClassRunner.possiblyExpectingExceptions(FrameworkMethod, Object, Statement)except that the expected exception is retrieved usinggetExpectedException(FrameworkMethod).- 覆盖:
possiblyExpectingExceptions在类中org.junit.runners.BlockJUnit4ClassRunner
-
getExpectedException
@Nullable protected Class<? extends Throwable> getExpectedException(org.junit.runners.model.FrameworkMethod frameworkMethod) Get theexceptionthat the supplied test method is expected to throw.Supports JUnit's
@Test(expected=...)annotation.Can be overridden by subclasses.
- 返回:
- the expected exception, or
nullif none was specified
-
withPotentialTimeout
protected org.junit.runners.model.Statement withPotentialTimeout(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement next) Perform the same logic asBlockJUnit4ClassRunner.withPotentialTimeout(FrameworkMethod, Object, Statement)but with additional support for Framework's@Timedannotation.Supports both Framework's
@Timedand JUnit's@Test(timeout=...)annotations, but not both simultaneously.- 覆盖:
withPotentialTimeout在类中org.junit.runners.BlockJUnit4ClassRunner- 返回:
- either a
FailOnTimeout, aFailOnTimeout, or the suppliedStatementas appropriate - 另请参阅:
-
getJUnitTimeout
protected long getJUnitTimeout(org.junit.runners.model.FrameworkMethod frameworkMethod) Retrieve the configured JUnittimeoutfrom the@Testannotation on the supplied test method.- 返回:
- the timeout, or
0if none was specified
-
getInfraTimeout
protected long getInfraTimeout(org.junit.runners.model.FrameworkMethod frameworkMethod) Retrieve the configured Infra-specifictimeoutfrom the@Timedannotation on the supplied test method.- 返回:
- the timeout, or
0if none was specified - 另请参阅:
-
withBeforeTestExecutionCallbacks
protected org.junit.runners.model.Statement withBeforeTestExecutionCallbacks(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement statement) Wrap the suppliedStatementwith aRunBeforeTestExecutionCallbacksstatement, thus preserving the default functionality while adding support for the TestContext Framework. -
withAfterTestExecutionCallbacks
protected org.junit.runners.model.Statement withAfterTestExecutionCallbacks(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement statement) Wrap the suppliedStatementwith aRunAfterTestExecutionCallbacksstatement, thus preserving the default functionality while adding support for the TestContext Framework. -
withBefores
protected org.junit.runners.model.Statement withBefores(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement statement) Wrap theStatementreturned by the parent implementation with aRunBeforeTestMethodCallbacksstatement, thus preserving the default functionality while adding support for the Infra TestContext Framework.- 覆盖:
withBefores在类中org.junit.runners.BlockJUnit4ClassRunner- 另请参阅:
-
withAfters
protected org.junit.runners.model.Statement withAfters(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement statement) Wrap theStatementreturned by the parent implementation with aRunAfterTestMethodCallbacksstatement, thus preserving the default functionality while adding support for the Infra TestContext Framework.- 覆盖:
withAfters在类中org.junit.runners.BlockJUnit4ClassRunner- 另请参阅:
-
withPotentialRepeat
protected org.junit.runners.model.Statement withPotentialRepeat(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement next)
-