类 SpringClassRule
- java.lang.Object
- org.springframework.test.context.junit4.rules.SpringClassRule
- 所有已实现的接口:
TestRule
public class SpringClassRule extends Object implements TestRule
SpringClassRule
is a custom JUnitTestRule
that supports class-level features of the Spring TestContext Framework in standard JUnit tests by means of theTestContextManager
and associated support classes and annotations.In contrast to the
SpringJUnit4ClassRunner
, Spring's rule-based JUnit support has the advantage that it is independent of anyRunner
and can therefore be combined with existing alternative runners like JUnit'sParameterized
or third-party runners such as theMockitoJUnitRunner
.In order to achieve the same functionality as the
SpringJUnit4ClassRunner
, however, aSpringClassRule
must be combined with aSpringMethodRule
, sinceSpringClassRule
only supports the class-level features of theSpringJUnit4ClassRunner
.Example Usage
public class ExampleSpringIntegrationTest { @ClassRule public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule(); @Rule public final SpringMethodRule springMethodRule = new SpringMethodRule(); // ... }
The following list constitutes all annotations currently supported directly or indirectly by
SpringClassRule
. (Note that additional annotations may be supported by variousTestExecutionListener
orTestContextBootstrapper
implementations.)NOTE: As of Spring Framework 4.3, this class requires JUnit 4.12 or higher.
- 从以下版本开始:
- 4.2
- 作者:
- Sam Brannen, Philippe Marschall
- 另请参阅:
apply(Statement, Description)
,SpringMethodRule
,TestContextManager
,SpringJUnit4ClassRunner
构造器概要
构造器 构造器 说明 SpringClassRule()
构造器详细资料
SpringClassRule
public SpringClassRule()
方法详细资料
apply
public Statement apply(Statement base, Description description)
Apply class-level features of the Spring TestContext Framework to the suppliedbase
statement.Specifically, this method retrieves the
TestContextManager
used by this rule and its associatedSpringMethodRule
and invokes thebeforeTestClass()
andafterTestClass()
methods on theTestContextManager
.In addition, this method checks 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 ofbeforeTestClass()
methods inTestExecutionListeners
.- 指定者:
apply
在接口中TestRule
- 参数:
base
- the baseStatement
that this rule should be applied todescription
- aDescription
of the current test execution- 返回:
- a statement that wraps the supplied
base
with class-level features of the Spring TestContext Framework - 另请参阅:
getTestContextManager(java.lang.Class<?>)
,withBeforeTestClassCallbacks(org.junit.runners.model.Statement, org.springframework.test.context.TestContextManager)
,withAfterTestClassCallbacks(org.junit.runners.model.Statement, org.springframework.test.context.TestContextManager)
,withProfileValueCheck(org.junit.runners.model.Statement, java.lang.Class<?>)
,withTestContextManagerCacheEviction(org.junit.runners.model.Statement, java.lang.Class<?>)