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

Spring Batch @SpringBatchTest 注解

作者头像
HoneyMoose
修改2019-01-21 10:29:37
修改2019-01-21 10:29:37
9000
举报
文章被收录于专栏:CWIKIUSCWIKIUS

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

代码语言:javascript
复制
@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 章节中的内容。

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档