首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Spring Batch @SpringBatchTest 注解

Spring Batch @SpringBatchTest 注解

作者头像
HoneyMoose
发布于 2019-01-30 10:06:46
发布于 2019-01-30 10:06:46
1.1K0
举报
文章被收录于专栏:iSharkFlyiSharkFly

Spring Batch 提供了一些非常有用的工具类(例如 JobLauncherTestUtils 和 JobRepositoryTestUtils)和测试执行监听器(StepScopeTestExecutionListener 和 JobScopeTestExecutionListener)来测试批量组件。然而, 为了能够使用这些工具类,你必须明确的对它们进行配置。这个发布介绍了一个新的注解,这个注解被命名为 @SpringBatchTest 能够自动的添加工具 bean(utility beans)和监听器(listeners)来测试上下文并且为自动写入来标记为可用,下面是一个示例代码:

@RunWith(SpringRunner.class) @SpringBatchTest @ContextConfiguration(classes = {JobConfiguration.class}) public class JobTest {      @Autowired    private JobLauncherTestUtils jobLauncherTestUtils;      @Autowired    private JobRepositoryTestUtils jobRepositoryTestUtils;        @Before    public void clearMetadata() {       jobRepositoryTestUtils.removeJobExecutions();    }      @Test    public void testJob() throws Exception {       // given       JobParameters jobParameters =             jobLauncherTestUtils.getUniqueJobParameters();         // when       JobExecution jobExecution =             jobLauncherTestUtils.launchJob(jobParameters);         // then       Assert.assertEquals(ExitStatus.COMPLETED,                           jobExecution.getExitStatus());    }   }

有关这个新注解的更多细节,请参考 Unit Testing 章节中的内容。

https://www.cwiki.us/display/SpringBatchZH/@SpringBatchTest+Annotation

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档