title: Spring Batch End to End Test configuration not working
body: <p>I followed the official Spring batch guide (<a href="https://spring.io/guides/gs/batch-processing/" rel="nofollow noreferrer">https://spring.io/guides/gs/batch-processing/</a>) and successfully did the example. For the same job, I am trying to create an end to end integration test. Especially I am using only test configuration. That is in my test I am defining all the needed beans. So this should be the only configuration needed to run the job. This gives a lot of flexibility. The test fails when creating ApplicationContext. It is complaining that it cannot find the Datasource. When I run the actual application, since I am using an in-memory database spring automatically creates the data source and spring batch related tables in the database. But when I run my test it is not automatically creating the database. How can I trigger spring to do that? </p>
  
  <p>In my test configuration when I added explicit data source bean configuration it created the data source but it did not create the spring batch related tables in the database.</p>
  
  <p>Below is the Test code:</p>
  
  <pre><code>@SpringBatchTest
  @RunWith(SpringRunner.class)
  public class PersonJobTest {
  
      @Autowired
      private JobLauncherTestUtils jobLauncherTestUtils;
  
      @Test
      public void testPersonJob() throws Exception{
  
          JobExecution jobExecution = jobLauncherTestUtils.launchJob();
          assertEquals("COMPLETED", jobExecution.getExitStatus().getExitCode());
      }
  
  
      @Configuration
      @EnableBatchProcessing
      public static class JobConfig {
  
          @Autowired
          public JobBuilderFactory jobBuilderFactory;
  
          @Autowired
          public StepBuilderFactory stepBuilderFactory;
  
          private JdbcTemplate simpleJdbcTemplate;
  
          @Bean
          public FlatFileItemReader&lt;Person&gt; reader() {
              return new FlatFileItemReaderBuilder&lt;Person&gt;()
                      .name("personItemReader")
                      .resource(new ClassPathResource("sample-data.csv"))
                      .delimited()
                      .names(new String[]{"firstName", "lastName"})
                      .fieldSetMapper(new BeanWrapperFieldSetMapper&lt;Person&gt;() {{
                          setTargetType(Person.class);
                      }})
                      .build();
          }
  
          @Bean
          public PersonItemProcessor processor() {
              return new PersonItemProcessor();
          }
  
          @Bean
          @Autowired
          public JdbcBatchItemWriter&lt;Person&gt; writer(DataSource dataSource) {
              return new JdbcBatchItemWriterBuilder&lt;Person&gt;()
                      .itemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider&lt;&gt;())
                      .sql("INSERT INTO people (first_name, last_name) VALUES (:firstName, :lastName)")
                      .dataSource(dataSource)
                      .build();
          }
  
          @Bean
          public JdbcTemplate jdbcTemplate(DataSource dataSource) {
              return new JdbcTemplate(dataSource);
          }
  
          @Bean
          public JobCompletionNotificationListener getListener(JdbcTemplate jdbcTemplate){
              return new JobCompletionNotificationListener(jdbcTemplate);
          }
  
          @Bean
          public Job importUserJob(JobCompletionNotificationListener listener, Step step1) {
              return jobBuilderFactory.get("importUserJob")
                      .incrementer(new RunIdIncrementer())
                      .listener(listener)
                      .flow(step1)
                      .end()
                      .build();
          }
  
          @Bean
          public Step step1(JdbcBatchItemWriter&lt;Person&gt; writer) {
              return stepBuilderFactory.get("step1")
                      .&lt;Person, Person&gt; chunk(10)
                      .reader(reader())
                      .processor(processor())
                      .writer(writer)
                      .build();
          }
      }
  
  
  }
  </code></pre>
  
  <p>pom.xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.1.4.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;com.intuit.iip.dg.dgworkflow&lt;/groupId&gt;
      &lt;artifactId&gt;dg-workflow-springbatch-poc&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;dg-workflow-springbatch-poc&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-batch&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
              &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.batch&lt;/groupId&gt;
              &lt;artifactId&gt;spring-batch-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>When running the test I want spring boot to auto-configure the data source and also create spring batch related tables like it does when I run the actual application.</p>