Testing SpringBatch:测试JobExecutionListener

Testing SpringBatch:测试JobExecutionListener,testing,listener,spring-batch,jobs,Testing,Listener,Spring Batch,Jobs,我得到了一个JobExecutionListener,如下所示: public class JobListener implements JobExecutionListener { @Override public void beforeJob(final JobExecution jobExecution) { // do some work with the jobExecution } @Override public void

我得到了一个
JobExecutionListener
,如下所示:

public class JobListener implements JobExecutionListener {

    @Override
    public void beforeJob(final JobExecution jobExecution) {
        // do some work with the jobExecution
    }

    @Override
    public void afterJob(final JobExecution jobExecution) {
        // do some work with the jobExecution
    }
}

我想为我的JobListener编写一个测试,我想知道自己是否需要模拟JobExecution。您认为这样可以吗,或者有其他很好的解决方案吗?

Spring batch附带了一个很好的测试框架。
将以下内容添加到pom.xml中

<dependency>   
 <groupId>org.springframework.batch</groupId>
    <artifactId>spring-batch-test</artifactId>
    <version>${spring.batch.version}</version>
    <scope>test</scope>
</dependency>
如果要将其转换为集成测试,请编写包含一些模拟作业的作业xml片段,并使用org.springframework.batch.test.JobLauncherTestUtils
有关更多信息,请参阅

JobListener jobListener = new JobListener ()
//Create a JobExecution (You have 6 overloaded methods choose the one you like)
JobExecution jobExecution = MetaDataInstanceFactory.createJobExecution(..);
jobListener.beforeJob(jobExecution);
jobListener.afterJob(jobExecution);