类 StepScopeTestExecutionListener

  • 所有已实现的接口:
    org.springframework.test.context.TestExecutionListener

    public class StepScopeTestExecutionListener
    extends java.lang.Object
    implements org.springframework.test.context.TestExecutionListener
    A TestExecutionListener that sets up step-scope context for dependency injection into unit tests. A StepContext will be created for the duration of a test method and made available to any dependencies that are injected. The default behaviour is just to create a StepExecution with fixed properties. Alternatively it can be provided by the test case as a factory methods returning the correct type. Example:
     @ContextConfiguration
     @TestExecutionListeners( { DependencyInjectionTestExecutionListener.class, StepScopeTestExecutionListener.class })
     @RunWith(SpringJUnit4ClassRunner.class)
     public class StepScopeTestExecutionListenerIntegrationTests {
     
            // A step-scoped dependency configured in the ApplicationContext
            @Autowired
            private ItemReader<String> reader;
     
      public StepExecution getStepExecution() {
        StepExecution execution = MetaDataInstanceFactory.createStepExecution();
        execution.getExecutionContext().putString("foo", "bar");
        return execution;
      }
     
            @Test
            public void testStepScopedReader() {
                    // Step context is active here so the reader can be used,
          // and the step execution context will contain foo=bar...
                    assertNotNull(reader.read());
            }
     
     }
     
    作者:
    Dave Syer, Chris Schaefer
    • 方法概要

      所有方法 实例方法 具体方法 
      修饰符和类型方法说明
      voidafterTestClass​(org.springframework.test.context.TestContext testContext) 
      voidafterTestMethod​(org.springframework.test.context.TestContext testContext) 
      voidbeforeTestClass​(org.springframework.test.context.TestContext testContext) 
      voidbeforeTestMethod​(org.springframework.test.context.TestContext testContext) 
      protected StepExecutiongetStepExecution​(org.springframework.test.context.TestContext testContext)
      Discover a StepExecution as a field in the test case or create one if none is available.
      voidprepareTestInstance​(org.springframework.test.context.TestContext testContext)
      Set up a StepExecution as a test context attribute.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • 从接口继承的方法 org.springframework.test.context.TestExecutionListener

        afterTestExecution, beforeTestExecution
    • 方法详细资料

      • prepareTestInstance

        public void prepareTestInstance​(org.springframework.test.context.TestContext testContext)
                                 throws java.lang.Exception
        Set up a StepExecution as a test context attribute.
        指定者:
        prepareTestInstance 在接口中 org.springframework.test.context.TestExecutionListener
        参数:
        testContext - the current test context
        抛出:
        java.lang.Exception - if there is a problem
        另请参阅:
        TestExecutionListener.prepareTestInstance(TestContext)
      • beforeTestMethod

        public void beforeTestMethod​(org.springframework.test.context.TestContext testContext)
                              throws java.lang.Exception
        指定者:
        beforeTestMethod 在接口中 org.springframework.test.context.TestExecutionListener
        参数:
        testContext - the current test context
        抛出:
        java.lang.Exception - if there is a problem
        另请参阅:
        TestExecutionListener.beforeTestMethod(TestContext)
      • afterTestMethod

        public void afterTestMethod​(org.springframework.test.context.TestContext testContext)
                             throws java.lang.Exception
        指定者:
        afterTestMethod 在接口中 org.springframework.test.context.TestExecutionListener
        参数:
        testContext - the current test context
        抛出:
        java.lang.Exception - if there is a problem
        另请参阅:
        TestExecutionListener.afterTestMethod(TestContext)
      • afterTestClass

        public void afterTestClass​(org.springframework.test.context.TestContext testContext)
                            throws java.lang.Exception
        指定者:
        afterTestClass 在接口中 org.springframework.test.context.TestExecutionListener
        抛出:
        java.lang.Exception
      • beforeTestClass

        public void beforeTestClass​(org.springframework.test.context.TestContext testContext)
                             throws java.lang.Exception
        指定者:
        beforeTestClass 在接口中 org.springframework.test.context.TestExecutionListener
        抛出:
        java.lang.Exception
      • getStepExecution

        protected StepExecution getStepExecution​(org.springframework.test.context.TestContext testContext)
        Discover a StepExecution as a field in the test case or create one if none is available.
        参数:
        testContext - the current test context
        返回:
        a StepExecution