类 InfraMethodRule
- 所有已实现的接口:
org.junit.rules.MethodRule
ApplicationMethodRule is a custom JUnit 4 MethodRule that
supports instance-level and method-level features of the
TestContext Framework in standard JUnit tests by means
of the TestContextManager and associated support classes and
annotations.
In contrast to the JUnit4ClassRunner, Framework's rule-based JUnit support has the advantage
that it is independent of any Runner and
can therefore be combined with existing alternative runners like JUnit's
Parameterized or third-party runners such as the MockitoJUnitRunner.
In order to achieve the same functionality as the JUnit4ClassRunner,
however, a ApplicationMethodRule must be combined with a InfraClassRule,
since ApplicationMethodRule only supports the instance-level and method-level
features of the JUnit4ClassRunner.
Example Usage
public class ExampleInfraIntegrationTest {
@ClassRule
public static final ApplicationClassRule applicationClassRule = new ApplicationClassRule();
@Rule
public final ApplicationMethodRule applicationMethodRule = new ApplicationMethodRule();
// ...
}
The following list constitutes all annotations currently supported directly
or indirectly by ApplicationMethodRule. (Note that additional annotations
may be supported by various
TestExecutionListener or
TestContextBootstrapper
implementations.)
NOTE: this class requires JUnit 4.12 or higher.
WARNING: Due to the shortcomings of JUnit rules, the
ApplicationMethodRule
prepares the test instance before @Before lifecycle methods instead of
immediately after instantiation of the test class. In addition, the
ApplicationMethodRule does not support the
beforeTestExecution() and afterTestExecution() callbacks of the
TestExecutionListener
API.
- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen, Philippe Marschall
- 另请参阅:
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明org.junit.runners.model.Statementapply(org.junit.runners.model.Statement base, org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance) Apply instance-level and method-level features of the TestContext Framework to the suppliedbasestatement.private org.junit.runners.model.StatementwithAfterTestMethodCallbacks(org.junit.runners.model.Statement next, Method testMethod, Object testInstance, TestContextManager testContextManager) Wrap the suppliedStatementwith aRunAfterTestMethodCallbacksstatement.private org.junit.runners.model.StatementwithBeforeTestMethodCallbacks(org.junit.runners.model.Statement next, Method testMethod, Object testInstance, TestContextManager testContextManager) Wrap the suppliedStatementwith aRunBeforeTestMethodCallbacksstatement.private org.junit.runners.model.StatementwithPotentialRepeat(org.junit.runners.model.Statement next, Method testMethod, Object testInstance) Wrap the suppliedStatementwith aRepeatTeststatement.private org.junit.runners.model.StatementwithPotentialTimeout(org.junit.runners.model.Statement next, Method testMethod, Object testInstance) Wrap the suppliedStatementwith aFailOnTimeoutstatement.private org.junit.runners.model.StatementwithProfileValueCheck(org.junit.runners.model.Statement next, Method testMethod, Object testInstance) Wrap the suppliedStatementwith aProfileValueCheckerstatement.private org.junit.runners.model.StatementwithTestInstancePreparation(org.junit.runners.model.Statement next, Object testInstance, TestContextManager testContextManager) Wrap the suppliedStatementwith aRunPrepareTestInstanceCallbacksstatement.
-
字段详细资料
-
logger
private static final cn.taketoday.logging.Logger logger
-
-
构造器详细资料
-
InfraMethodRule
public InfraMethodRule()
-
-
方法详细资料
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runners.model.FrameworkMethod frameworkMethod, Object testInstance) Apply instance-level and method-level features of the TestContext Framework to the suppliedbasestatement.Specifically, this method invokes the
prepareTestInstance(),beforeTestMethod(), andafterTestMethod()methods on theTestContextManager, potentially with Infra timeouts and repetitions.In addition, this method checks whether the test is enabled in the current execution environment. This prevents methods with a non-matching
@IfProfileValueannotation from running altogether, even skipping the execution ofprepareTestInstance()methods inTestExecutionListeners.- 指定者:
apply在接口中org.junit.rules.MethodRule- 参数:
base- the baseStatementthat this rule should be applied toframeworkMethod- the method which is about to be invoked on the test instancetestInstance- the current test instance- 返回:
- a statement that wraps the supplied
basewith instance-level and method-level features of the TestContext Framework - 另请参阅:
-
withBeforeTestMethodCallbacks(org.junit.runners.model.Statement, java.lang.reflect.Method, java.lang.Object, cn.taketoday.test.context.TestContextManager)withAfterTestMethodCallbacks(org.junit.runners.model.Statement, java.lang.reflect.Method, java.lang.Object, cn.taketoday.test.context.TestContextManager)withPotentialRepeat(org.junit.runners.model.Statement, java.lang.reflect.Method, java.lang.Object)withPotentialTimeout(org.junit.runners.model.Statement, java.lang.reflect.Method, java.lang.Object)withTestInstancePreparation(org.junit.runners.model.Statement, java.lang.Object, cn.taketoday.test.context.TestContextManager)withProfileValueCheck(org.junit.runners.model.Statement, java.lang.reflect.Method, java.lang.Object)
-
withBeforeTestMethodCallbacks
private org.junit.runners.model.Statement withBeforeTestMethodCallbacks(org.junit.runners.model.Statement next, Method testMethod, Object testInstance, TestContextManager testContextManager) Wrap the suppliedStatementwith aRunBeforeTestMethodCallbacksstatement. -
withAfterTestMethodCallbacks
private org.junit.runners.model.Statement withAfterTestMethodCallbacks(org.junit.runners.model.Statement next, Method testMethod, Object testInstance, TestContextManager testContextManager) Wrap the suppliedStatementwith aRunAfterTestMethodCallbacksstatement. -
withTestInstancePreparation
private org.junit.runners.model.Statement withTestInstancePreparation(org.junit.runners.model.Statement next, Object testInstance, TestContextManager testContextManager) Wrap the suppliedStatementwith aRunPrepareTestInstanceCallbacksstatement. -
withPotentialRepeat
private org.junit.runners.model.Statement withPotentialRepeat(org.junit.runners.model.Statement next, Method testMethod, Object testInstance) - 另请参阅:
-
withPotentialTimeout
private org.junit.runners.model.Statement withPotentialTimeout(org.junit.runners.model.Statement next, Method testMethod, Object testInstance) - 另请参阅:
-
withProfileValueCheck
private org.junit.runners.model.Statement withProfileValueCheck(org.junit.runners.model.Statement next, Method testMethod, Object testInstance) Wrap the suppliedStatementwith aProfileValueCheckerstatement.- 另请参阅:
-