title: maven springboot test not running integration tests with specific datasource bean
body: <p>I have been struggling for a couple of days with spring testing.
  We are using maven-failsafe-plugin and using docker containers for our two specific databases.</p>
  <p>But when we include the non-primary datasource configuration, no tests are run.</p>
  <p>So config is (docker-maven-plugin sets the ip/host system properties for us):</p>
  <pre><code>metadata:
    datasource:
      url: jdbc:mariadb://${docker.mariadb.ip}:${docker.mariadb.port}/METADATA
      password: m_user
      username: m_pswd
  
  reporting:
    datasource:
      jdbcUrl: jdbc:vertica://${docker.vertica.ip}:${docker.vertica.port}/REPORTING?allowMultiQueries=true
      username: v_user
      password: v_pswd
  </code></pre>
  <p>We have two database configuration classes.</p>
  <pre><code>@Configuration
  @EnableTransactionManagement
  @EnableJpaRepositories(
          entityManagerFactoryRef = &quot;entityManagerFactory&quot;,
          basePackages = {&quot;com.company.application&quot;}
  )
  public class MariadbConfiguration {
  
      @Bean
      @Primary
      @ConfigurationProperties(prefix = &quot;metadata.datasource&quot;)
      public DataSourceProperties reportingDataSourceProperties() {
          return new DataSourceProperties();
      }
  
  
      @Primary
      @Bean(name = &quot;dataSource&quot;)
      @ConfigurationProperties(prefix = &quot;metadata.datasource&quot;)
      public HikariDataSource dataSource(DataSourceProperties mariadbDataSourceProperties) {
          return (HikariDataSource) mariadbDataSourceProperties.initializeDataSourceBuilder()
                  .type(HikariDataSource.class).build();
      }
  
      @Primary
      @Bean(name = &quot;entityManagerFactory&quot;)
      public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder, @Qualifier(&quot;dataSource&quot;) DataSource dataSource) {
          ...
      }
  
      @Primary
      @Bean(name = &quot;transactionManager&quot;)
      public PlatformTransactionManager transactionManager(@Qualifier(&quot;entityManagerFactory&quot;)
              EntityManagerFactory entityManagerFactory) {
          return new JpaTransactionManager(entityManagerFactory);
      }
  
      @Primary
      @Bean(name = &quot;transactionTemplate&quot;)
      public TransactionTemplate transactionTemplate(@Qualifier(&quot;transactionManager&quot;)
              PlatformTransactionManager transactionManager) {
          return new TransactionTemplate(transactionManager);
      }
  }
  </code></pre>
  <p>And</p>
  <pre><code>@Configuration
  public class VerticaConfiguration {
  
      @Bean(&quot;verticaDataSourceProperties&quot;)
      @ConfigurationProperties(prefix = &quot;reporting.datasource&quot;)
      public DataSourceProperties verticaDataSourceProperties() {
          return new DataSourceProperties();
      }
  
      @Bean(name = &quot;verticaDataSource&quot;)
      @ConfigurationProperties(prefix = &quot;reporting.datasource&quot;)
      public HikariDataSource verticaDataSource() {
          return (HikariDataSource) verticaDataSourceProperties().initializeDataSourceBuilder()
                  .type(HikariDataSource.class).build();
      }
  
      @Bean(name = &quot;verticaJdbcTemplate&quot;)
      public JdbcTemplate verticaJdbcTemplate() {
          return new JdbcTemplate(verticaDataSource());
      }
  }
  </code></pre>
  <p>So our test class is:</p>
  <pre><code>@RunWith(SpringRunner.class)
  @ActiveProfiles(&quot;itest&quot;)
  @ContextConfiguration(classes={MariadbConfiguration.class, VerticaConfiguration.class})
  @AutoConfigureTestDatabase(replace=AutoConfigureTestDatabase.Replace.NONE)
  @DataJpaTest
  public class ApplicationIT {
  
      @Autowired
      DataSource mariadb;
  
      @Qualifier(&quot;verticaDataSource&quot;)
      @Autowired
      DataSource vertica;
      
      @Test
      public void testApplicationLoaded() {}
  
  }
  </code></pre>
  <p>So if we <code>mvn verify</code> this no tests are run</p>
  <pre><code>[INFO] --- maven-failsafe-plugin:2.22.2:integration-test (default) @ our-application ---
  [INFO] 
  [INFO] -------------------------------------------------------
  [INFO]  T E S T S
  [INFO] -------------------------------------------------------
  [INFO] 
  [INFO] Results:
  [INFO] 
  [INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
  </code></pre>
  <p>BUT if we change the <code>@ContextConfigutation</code> to not include vertica</p>
  <pre><code>@ContextConfiguration(classes={MariadbConfiguration.class})
  </code></pre>
  <p>Then the test runs (and fails with bean initiasation error as expected)</p>
  <pre><code>
  [INFO] --- maven-failsafe-plugin:2.22.2:integration-test (default) @ our-application ---
  [INFO] 
  [INFO] -------------------------------------------------------
  [INFO]  T E S T S
  [INFO] -------------------------------------------------------
  ...
  [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 4.81 s &lt;&lt;&lt; FAILURE! - in com.company.application.test.ApplicationIT
  [ERROR] testApplicationLoaded  Time elapsed: 0.001 s  &lt;&lt;&lt; ERROR!
  org.springframework.beans.factory.UnsatisfiedDependencyException: ...
  ...
  [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
  </code></pre>
  <p>If we change the <code>@ContextConfigutation</code> to not include mariadb</p>
  <pre><code>@ContextConfiguration(classes={VerticaConfiguration.class})
  </code></pre>
  <p>Then no tests are run.</p>
  <p>Just to be clear, I am not asking about the error.</p>
  <p>The question is why does including the <code>VerticaConfiguration.class</code> mean no tests are run? Seems very weird. Application itself is fine, this is just a testing issue.</p>
  <p>Versions:</p>
  <ul>
  <li>java: 8</li>
  <li>spring boot: 2.2.6</li>
  <li>spring framework: 5.2.5</li>
  <li>junit: 4.12</li>
  </ul>
  <p>Part of our problem is we kind of inherited this project. So we use spring without properly understanding how it all hangs together.</p>