• S
    Introduce JUnit Rule alternative to SpringJUnit4ClassRunner · d1b1c4f8
    Sam Brannen 提交于
    Since Spring Framework 2.5, support for integrating the Spring
    TestContext Framework (TCF) into JUnit 4 based tests has been provided
    via the SpringJUnit4ClassRunner, but this approach precludes the
    ability for tests to be run with alternative runners like JUnit's
    Parameterized or third-party runners such as the MockitoJUnitRunner.
    
    This commit remedies this situation by introducing @ClassRule and @Rule
    based alternatives to the SpringJUnit4ClassRunner. These rules are
    independent of any Runner and can therefore be combined with
    alternative runners.
    
    Due to the limitations of JUnit's implementation of rules, as of JUnit
    4.12 it is currently impossible to create a single rule that can be
    applied both at the class level and at the method level (with access to
    the test instance). Consequently, this commit introduces the following
    two rules that must be used together.
    
     - SpringClassRule: a JUnit TestRule that provides the class-level
       functionality of the TCF to JUnit-based tests
    
     - SpringMethodRule: a JUnit MethodRule that provides the
       instance-level and method-level functionality of the TCF to
       JUnit-based tests
    
    In addition, this commit also introduces the following new JUnit
    Statements for use with rules:
    
     - RunPrepareTestInstanceCallbacks
    
     - ProfileValueChecker
    
    Issue: SPR-7731
    d1b1c4f8
ProgrammaticTxMgmtTests.java 9.2 KB