Spring Batch JUnit test for multiple jobs

前端 未结 5 2013
情深已故
情深已故 2020-12-16 20:24

I am having two jobs configured in one context file


        
            <         


        
5条回答
  •  情深已故
    2020-12-16 20:58

    Maybe late,

    but I found for myself working solution: manual configuration of JobLauncherTestUtils:

    @Inject
    @Qualifier(value = "Job1")
    private Job job;
    
    @Inject
    private JobLauncher jobLauncher;
    
    @Inject
    private JobRepository jobRepository;
    
    private JobLauncherTestUtils jobLauncherTestUtils;
    
    private void initailizeJobLauncherTestUtils() {
        this.jobLauncherTestUtils = new JobLauncherTestUtils();
        this.jobLauncherTestUtils.setJobLauncher(jobLauncher);
        this.jobLauncherTestUtils.setJobRepository(jobRepository);
        this.jobLauncherTestUtils.setJob(job);
    }
    
    @Before
    public void setUp() throws Exception {
        this.initailizeJobLauncherTestUtils();
    }
    

    with this you can control for which Job should JobLauncherTestUtils be applied. (by default it expects single Job configuration in context)

提交回复
热议问题