HoneyMoose
  • 首页
  • Java
  • Jersey
  • Jira
  • Confluence
  • U.S.
    • USRealEstate
    • USVisaTrack
    • H1B
  • 项目和网站
    • CWIKI.US
    • OSSEZ 社区
    • WIKI.OSSEZ.COM
    • BUG.OSSEZ.COM
    • RSS.OSSEZ.COM
BLOG.OSSEZ.COM
A responsive blog theme focused om user reading experience
  1. Home
  2. Computer Science
  3. Spring
  4. This article

Spring Batch @SpringBatchTest 注解

2019年01月18日 1205Browse 0Like 0Comments

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

Tags: Spring Spring Batch
Last updated:2019年01月18日

Kratos

stay absorbed stay excellent

Like
< Previous
Next >

Comments

Cancel reply

Newest Hotspots Random
Newest Hotspots Random
IntelliJ IDEA 2023.1 版本添加了包中类的列表功能 Jenkins 修改启动的端口 Spring 项目运行提示错误 Not a managed type Linux 查看 SELinux 的状态 WordPress 网站 Error Establishing a Database Connection(建立数据库连接时出错) Linux 开启或关闭 SELinux
Confluence 6 自定义 Decorator 模板的宏和针对高级用户 Git Clone 的时候遇到 Filename too long 错误 我该因为疫情而放弃美国绿卡吗 基于 Confluence 6 数据中心的 SAML 单点登录设置 SSL/TLS IT 技术岗位 2019 年北美求职流水账 Windows 11 修改 PIN 的长度为 4 位
Categories
  • Algorithm(算法)
  • AMQP
  • Angular
  • CI
  • Compile And CI
  • Computer Science
  • Confluence
  • DataBase
  • Gradle
  • H1B
  • Hibernate
  • IDE
  • Java
  • Jersey
  • Jira
  • MariaDB
  • PrestaShop
  • Spring
  • Spring Batch
  • U.S.
  • USRealEstate
  • USVisaTrack
  • 我的小厨

COPYRIGHT © 2020 HoneyMoose. ALL RIGHTS RESERVED.

THEME CWIKIUS.CN MADE BY VTROIS