open class SpringClassRule : TestRule
SpringClassRule
is a custom JUnit TestRule that supports class-level features of the Spring TestContext Framework in standard JUnit tests by means of the TestContextManager and associated support classes and annotations.
In contrast to the org.springframework.test.context.junit4.SpringJUnit4ClassRunner, Spring's rule-based JUnit support has the advantage that it is independent of any org.junit.runner.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 SpringJUnit4ClassRunner
, however, a SpringClassRule
must be combined with a SpringMethodRule, since SpringClassRule
only supports the class-level features of the SpringJUnit4ClassRunner
.
public class ExampleSpringIntegrationTest { @ClassRule public static final SpringClassRule springClassRule = 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 various org.springframework.test.context.TestExecutionListener or org.springframework.test.context.TestContextBootstrapper implementations.)
NOTE: As of Spring Framework 4.3, this class requires JUnit 4.12 or higher.
Author
Sam Brannen
Author
Philippe Marschall
Since
4.2
See Also
#apply(Statement, Description)SpringMethodRuleorg.springframework.test.context.TestContextManagerorg.springframework.test.context.junit4.SpringJUnit4ClassRunner
SpringClassRule()
In contrast to the org.springframework.test.context.junit4.SpringJUnit4ClassRunner, Spring's rule-based JUnit support has the advantage that it is independent of any org.junit.runner.Runner and can therefore be combined with existing alternative runners like JUnit's In order to achieve the same functionality as the
The following list constitutes all annotations currently supported directly or indirectly by
NOTE: As of Spring Framework 4.3, this class requires JUnit 4.12 or higher. |
open fun apply(base: Statement, description: Description): Statement
Apply class-level features of the Spring TestContext Framework to the supplied Specifically, this method retrieves the TestContextManager used by this rule and its associated SpringMethodRule and invokes the In addition, this method checks whether the test is enabled in the current execution environment. This prevents classes with a non-matching |