如何在 spring 批处理 junit 中分配作业名称

How is job name getting assigned in spring batch junit

我正在 junit 中测试 spring 批处理作业。

public void testJob() {
    JobExecution jobExecution = jobLauncherTestUtils.launchStep("processFileStep", params2, executionContext);

    JobParameters params3 = new JobParameters(setJobParams());

    jobLauncherTestUtils.launchStep("downloadResultsFile", params3, executionContext);

    Collection<StepExecution> actualStepExecutions = jobExecution.getStepExecutions();

    assertThat(actualStepExecutions.size(), is(1));

    assertThat(jobExecution.getJobInstance().getJobName(), is("TestJob"));// where is it set to TestJob?
}

我不明白如何将作业名称设置为 TestJob。 ?谢谢你的时间。

当您使用 JobLauncherTestUtils 启动一个步骤时,Spring Batch 将围绕您的步骤创建一个类型为 SimpleJob 的名为 TestJob 的单步作业并启动它。您可以在代码 here.

中看到这一点

这似乎没有记录,所以我创建了 an issue 来改进这方面的文档。