类 JUnit4ClassRunner

java.lang.Object
org.junit.runner.Runner
org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
org.junit.runners.BlockJUnit4ClassRunner
cn.taketoday.test.context.junit4.JUnit4ClassRunner
所有已实现的接口:
org.junit.runner.Describable, org.junit.runner.manipulation.Filterable, org.junit.runner.manipulation.Orderable, org.junit.runner.manipulation.Sortable
直接已知子类:
InfraRunner

public class JUnit4ClassRunner extends org.junit.runners.BlockJUnit4ClassRunner
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.)

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.Logger
     
    private final TestContextManager
     
    private static final Method
     
  • 构造器概要

    构造器
    构造器
    说明
    Construct a new JUnit4ClassRunner and initialize a TestContextManager to provide Infra testing functionality to standard JUnit tests.
  • 方法概要

    修饰符和类型
    方法
    说明
    protected Object
    Delegate to the parent implementation for creating the test instance and then allow the TestContextManager to prepare the test instance before returning it.
    Create a new TestContextManager for the supplied test class.
    private static void
     
    org.junit.runner.Description
    Return a description suitable for an ignored test class if the test is disabled via @IfProfileValue at the class-level, and otherwise delegate to the parent implementation.
    protected Class<? extends Throwable>
    getExpectedException(org.junit.runners.model.FrameworkMethod frameworkMethod)
    Get the exception that the supplied test method is expected to throw.
    protected long
    getInfraTimeout(org.junit.runners.model.FrameworkMethod frameworkMethod)
    Retrieve the configured Infra-specific timeout from the @Timed annotation on the supplied test method.
    protected long
    getJUnitTimeout(org.junit.runners.model.FrameworkMethod frameworkMethod)
    Retrieve the configured JUnit timeout from the @Test annotation on the supplied test method.
    protected final TestContextManager
    Get the TestContextManager associated with this runner.
    protected boolean
    isTestMethodIgnored(org.junit.runners.model.FrameworkMethod frameworkMethod)
    Return true if @Ignore is present for the supplied test method or if the test method is disabled via @IfProfileValue.
    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.
    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 as BlockJUnit4ClassRunner.possiblyExpectingExceptions(FrameworkMethod, Object, Statement) except that the expected exception is retrieved using getExpectedException(FrameworkMethod).
    void
    run(org.junit.runner.notification.RunNotifier notifier)
    Check whether the test is enabled in the current execution environment.
    protected void
    runChild(org.junit.runners.model.FrameworkMethod frameworkMethod, org.junit.runner.notification.RunNotifier notifier)
    Perform the same logic as BlockJUnit4ClassRunner.runChild(FrameworkMethod, RunNotifier), except that tests are determined to be ignored by isTestMethodIgnored(FrameworkMethod).
    protected org.junit.runners.model.Statement
    withAfterClasses(org.junit.runners.model.Statement statement)
    Wrap the Statement returned by the parent implementation with a RunAfterTestClassCallbacks statement, thus preserving the default JUnit functionality while adding support for the TestContext Framework.
    protected org.junit.runners.model.Statement
    withAfters(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement statement)
    Wrap the Statement returned by the parent implementation with a RunAfterTestMethodCallbacks statement, thus preserving the default functionality while adding support for the Infra TestContext Framework.
    protected org.junit.runners.model.Statement
    withAfterTestExecutionCallbacks(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement statement)
    Wrap the supplied Statement with a RunAfterTestExecutionCallbacks statement, thus preserving the default functionality while adding support for the TestContext Framework.
    protected org.junit.runners.model.Statement
    withBeforeClasses(org.junit.runners.model.Statement statement)
    Wrap the Statement returned by the parent implementation with a RunBeforeTestClassCallbacks statement, thus preserving the default JUnit functionality while adding support for the Infra TestContext Framework.
    protected org.junit.runners.model.Statement
    withBefores(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement statement)
    Wrap the Statement returned by the parent implementation with a RunBeforeTestMethodCallbacks statement, thus preserving the default functionality while adding support for the Infra TestContext Framework.
    protected org.junit.runners.model.Statement
    withBeforeTestExecutionCallbacks(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement statement)
    Wrap the supplied Statement with a RunBeforeTestExecutionCallbacks statement, thus preserving the default functionality while adding support for the TestContext Framework.
    protected org.junit.runners.model.Statement
    withPotentialRepeat(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement next)
    Wrap the supplied Statement with a RepeatTest statement.
    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 as BlockJUnit4ClassRunner.withPotentialTimeout(FrameworkMethod, Object, Statement) but with additional support for Framework's @Timed annotation.
    private org.junit.runners.model.Statement
    withRulesReflectively(org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance, org.junit.runners.model.Statement statement)
    Invoke JUnit's private withRules() 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

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详细资料

    • logger

      private static final cn.taketoday.logging.Logger logger
    • withRulesMethod

      private static final Method withRulesMethod
    • testContextManager

      private final TestContextManager testContextManager
  • 构造器详细资料

    • JUnit4ClassRunner

      public JUnit4ClassRunner(Class<?> clazz) throws org.junit.runners.model.InitializationError
      Construct a new JUnit4ClassRunner and initialize a TestContextManager to provide Infra testing functionality to standard JUnit tests.
      参数:
      clazz - the test class to be run
      抛出:
      org.junit.runners.model.InitializationError
      另请参阅:
  • 方法详细资料

    • ensureInfraRulesAreNotPresent

      private static void ensureInfraRulesAreNotPresent(Class<?> testClass)
    • createTestContextManager

      protected TestContextManager createTestContextManager(Class<?> clazz)
      Create a new TestContextManager for the supplied test class.

      Can be overridden by subclasses.

      参数:
      clazz - the test class to be managed
    • getTestContextManager

      protected final TestContextManager getTestContextManager()
      Get the TestContextManager associated 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 @IfProfileValue at 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 @IfProfileValue annotation from running altogether, even skipping the execution of prepareTestInstance() methods in TestExecutionListeners.

      覆盖:
      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 the Statement returned by the parent implementation with a RunBeforeTestClassCallbacks statement, 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 the Statement returned by the parent implementation with a RunAfterTestClassCallbacks statement, thus preserving the default JUnit functionality while adding support for the TestContext Framework.
      覆盖:
      withAfterClasses 在类中 org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
      另请参阅:
    • createTest

      protected Object createTest() throws Exception
      Delegate to the parent implementation for creating the test instance and then allow the TestContextManager to 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 as BlockJUnit4ClassRunner.runChild(FrameworkMethod, RunNotifier), except that tests are determined to be ignored by isTestMethodIgnored(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 @Before and @After methods within the timed execution. Note that this differs from the default JUnit behavior of executing @Before and @After methods in the main thread while executing the actual test method in a separate thread. Thus, the net effect is that @Before and @After methods 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
      另请参阅:
    • 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 private withRules() method using reflection.
    • isTestMethodIgnored

      protected boolean isTestMethodIgnored(org.junit.runners.model.FrameworkMethod frameworkMethod)
      Return true if @Ignore is 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 as BlockJUnit4ClassRunner.possiblyExpectingExceptions(FrameworkMethod, Object, Statement) except that the expected exception is retrieved using getExpectedException(FrameworkMethod).
      覆盖:
      possiblyExpectingExceptions 在类中 org.junit.runners.BlockJUnit4ClassRunner
    • getExpectedException

      @Nullable protected Class<? extends Throwable> getExpectedException(org.junit.runners.model.FrameworkMethod frameworkMethod)
      Get the exception that the supplied test method is expected to throw.

      Supports JUnit's @Test(expected=...) annotation.

      Can be overridden by subclasses.

      返回:
      the expected exception, or null if 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 as BlockJUnit4ClassRunner.withPotentialTimeout(FrameworkMethod, Object, Statement) but with additional support for Framework's @Timed annotation.

      Supports both Framework's @Timed and JUnit's @Test(timeout=...) annotations, but not both simultaneously.

      覆盖:
      withPotentialTimeout 在类中 org.junit.runners.BlockJUnit4ClassRunner
      返回:
      either a FailOnTimeout, a FailOnTimeout, or the supplied Statement as appropriate
      另请参阅:
    • getJUnitTimeout

      protected long getJUnitTimeout(org.junit.runners.model.FrameworkMethod frameworkMethod)
      Retrieve the configured JUnit timeout from the @Test annotation on the supplied test method.
      返回:
      the timeout, or 0 if none was specified
    • getInfraTimeout

      protected long getInfraTimeout(org.junit.runners.model.FrameworkMethod frameworkMethod)
      Retrieve the configured Infra-specific timeout from the @Timed annotation on the supplied test method.
      返回:
      the timeout, or 0 if 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 supplied Statement with a RunBeforeTestExecutionCallbacks statement, 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 supplied Statement with a RunAfterTestExecutionCallbacks statement, 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 the Statement returned by the parent implementation with a RunBeforeTestMethodCallbacks statement, 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 the Statement returned by the parent implementation with a RunAfterTestMethodCallbacks statement, 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)
      Wrap the supplied Statement with a RepeatTest statement.

      Supports Framework's @Repeat annotation.

      另请参阅: