前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring Batch @SpringBatchTest 注解

Spring Batch @SpringBatchTest 注解

作者头像
HoneyMoose
修改2019-01-21 10:29:37
7540
修改2019-01-21 10:29:37
举报
文章被收录于专栏: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 条评论
热度
最新
推荐阅读
相关产品与服务
批量计算
批量计算(BatchCompute,Batch)是为有大数据计算业务的企业、科研单位等提供高性价比且易用的计算服务。批量计算 Batch 可以根据用户提供的批处理规模,智能地管理作业和调动其所需的最佳资源。有了 Batch 的帮助,您可以将精力集中在如何分析和处理数据结果上。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档