title: How to test the whole flow of a Spring Batch application?
body: <p>I have a Spring boot + batch application which reads a source CSV file, process it and write to target CSV file, I'm struggling with writing tests that will:
  use an input - "simpleFlowInput.csv" and compare the "simpleFlowActual.csv" output with an "simpleFlowExpected.csv" file, i would like to write many of these tests but struggle with the way to do it. </p>
  
  <p>My application contain only one step and one job:</p>
  
  <pre><code>@Bean("csvFileToFileStep")
  public Step csvFileToFileStep() {
      return stepBuilderFactory.get("csvFileToFileStep").&lt;RowInput, RowOutput&gt;chunk(10000).reader(csvRowsReader()).processor(csvRowsProcessor())
              .writer(compositeItemWriter()).build();
  }
  
  @Bean("csvFileToCsvJob")
  Job csvFileToCsvJob(JobCompletionNotificationListener listener) {
      return jobBuilderFactory.get("csvFileToCsvJob").incrementer(new RunIdIncrementer()).listener(listener).flow(csvFileToFileStep()).end()
              .build();
  }
  </code></pre>
  
  <p>My current test:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @Configuration
  @EnableBatchProcessing
  @SpringBootTest
  public class Tester{
  
      @Autowired
      Job csvFileToCsvJob;
      @Autowired
      Step csvFileToFileStep;
      @Autowired
      CsvFileReadProcessAndWriteConfig csvFileReadProcessAndWriteConfig;
      private JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils();
  
  
      @Test
      public void testSimpleFlow() throws Exception {
  
          ClassLoader classLoader = getClass().getClassLoader();
          File fileInput = new File(classLoader.getResource("simpleFlowInput.csv").getFile());
          File fileActual = new File(classLoader.getResource("simpleFlowActual.csv").getFile());
          File fileExpected = new File(classLoader.getResource("simpleFlowExpected.csv").getFile());
  
          FileManager.getInstance().setInputFileLocation(fileInput.toString());
          FileManager.getInstance().setOutputFileLocation(fileActual.toString());
  
          System.out.println(fileExpected.length());
          System.out.println(fileActual.length());
  
          Assert.assertTrue(fileExpected.length() == fileActual.length());
          AssertFile.assertFileEquals(fileExpected,fileActual);//compare
      }
  }
  </code></pre>
  
  <p>Any advise on how to test it ? </p>
  
  <p>( I found this question written at 2010 with a partial answer mentioning "JobLauncherTestUtils". <a href="https://stackoverflow.com/questions/4080735/what-is-the-best-way-to-test-job-flow-in-spring-batch">What is the best way to test job flow in Spring-Batch?</a> )</p>