1

I'm working with spring batch 4 with annotations and i have a java class for configuration like this :

@Autowired
public JobBuilderFactory jobBuilderFactory;

@Autowired
public StepBuilderFactory stepBuilderFactory;

@Bean
public Job firstJob() {
    return jobBuilderFactory.get("firstJob").incrementer(new RunIdIncrementer())
            .flow(firstStep()).end().build();
}

private Step firstStep () {
    return stepBuilderFactory.get("firstStep")
            .<Student, Student>chunk(100).reader(customReader())
            .processor(customProcessor()).writer(customWriter()).build();
}

@Bean
ItemReader<Student> CustomReader () {
    return new CustomReader ("students.xml");
}

@Bean
public CustomProcessor customProcessor () {
    return new CustomProcessor ();
}

@Bean
public CustomWriter customWriter () {
    return new CustomWriter ();
}

there is any way to test this class of configuration ? i can't found a way in spring documentation. CustomReader, CustomProcessor... already tested

3
  • Did you tried with Spy ? Commented Aug 30, 2018 at 23:39
  • No, i'm using mockito Commented Aug 31, 2018 at 7:37
  • 1
    You can find an example of how to test batch jobs here: docs.spring.io/spring-batch/4.0.x/reference/html/… Commented Aug 31, 2018 at 7:48

1 Answer 1

1

I'm not sure what version of spring boot you are using. But the way I've been testing configurations is with @SpringBootTest

@SpringBootTest(classes = {YourConfiguration.class}
YourConfigurationTest
{
    @Autowired
    private ApplicationContext context;

    @Test
    public void testBeans()
    {
         Job job = context.getBean(Job.class);
         Assert.notNull(job);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.