注释类型 SpringBatchTest
@Target(TYPE) @Retention(RUNTIME) @Documented @Inherited @TestExecutionListeners(listeners={StepScopeTestExecutionListener.class,JobScopeTestExecutionListener.class}, mergeMode=MERGE_WITH_DEFAULTS) public @interface SpringBatchTest
Annotation that can be specified on a test class that runs Spring Batch based tests. Provides the following features over the regular Spring TestContext Framework:- Registers a
JobLauncherTestUtils
bean with theBatchTestContextCustomizer.JOB_LAUNCHER_TEST_UTILS_BEAN_NAME
which can be used in tests for launching jobs and steps. - Registers a
JobRepositoryTestUtils
bean with theBatchTestContextCustomizer.JOB_REPOSITORY_TEST_UTILS_BEAN_NAME
which can be used in tests setup to create or remove job executions. - Registers the
StepScopeTestExecutionListener
andJobScopeTestExecutionListener
as test execution listeners which are required to test step/job scoped beans.
A typical usage of this annotation is like:
@RunWith(SpringRunner.class) @SpringBatchTest @ContextConfiguration(classes = MyBatchJobConfiguration.class) public class MyBatchJobTests { @@Autowired private JobLauncherTestUtils jobLauncherTestUtils; @@Autowired private JobRepositoryTestUtils jobRepositoryTestUtils; @Before public void clearJobExecutions() { this.jobRepositoryTestUtils.removeJobExecutions(); } @Test public void testMyJob() throws Exception { // given JobParameters jobParameters = this.jobLauncherTestUtils.getUniqueJobParameters(); // when JobExecution jobExecution = this.jobLauncherTestUtils.launchJob(jobParameters); // then Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus()); } }
- 从以下版本开始:
- 4.1
- 作者:
- Mahmoud Ben Hassine
- 另请参阅:
JobLauncherTestUtils
,JobRepositoryTestUtils
,StepScopeTestExecutionListener
,JobScopeTestExecutionListener
- Registers a