为什么在 Spring 批测试中需要 JobLauncherTestUtils 和 JobRepositoryTestUtils?

Why would I need JobLauncherTestUtils and JobRepositoryTestUtils in Spring Batch Testing?

为什么在测试 Spring 批处理项目时需要使用 JobLauncherTestUtils 和 JobRepositoryTestUtils 而不是 JobLauncher 和 JobRepository?它们有什么区别?

JobLauncherTestUtils具有以下优点:

  • 能够运行工作中的一个步骤
  • 能够为每个 运行
  • 获得唯一的 JobParameters 实例

JobRepositoryTestUtils具有以下优点:

  • 用于创建 JobExecution 可用作测试装置的实例的实用方法
  • 用于删除特定 JobExecution 或清理整个作业存储库的实用方法(在每次测试之后或之前很有用)

详情请参考每个 class 的 javadoc。