title: spring boot test application.properties file not found
body: <p>I have a maven module with one test class <strong>DbTest</strong>. When running the test, the  property file  application.properties is not picked up. The line
   <strong>System.out.println</strong> in <strong>DvsTestDbConfig</strong>  displays  {database.test} instead of qqqqqqqqq (dummy value for the moment).  Any idea why spring doesn't find the property file ?</p>
  
  <p><a href="https://i.stack.imgur.com/iJmVo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iJmVo.png" alt="Projectstructure"></a></p>
  
  <p>DbTest</p>
  
  <pre><code>package ch.admin.estv.dvs.test.database;
  
  import ch.admin.estv.dvs.test.database.config.DvsTestDbConfig;
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.springframework.context.annotation.Import;
  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  
  @RunWith(SpringJUnit4ClassRunner.class)
  @Import(DvsTestDbConfig.class)
  public class DbTest {
  
      @Test
      public void givenPartnerToDelete_whenPartnerDelete_thenNoEntryExist() {
  
          System.out.println("test started");
      }
  }   
  </code></pre>
  
  <p>DvsTestDbConfig</p>
  
  <pre><code>package ch.admin.estv.dvs.test.database.config;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.core.env.Environment;
  import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
  import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  import org.springframework.jdbc.datasource.DriverManagerDataSource;
  import org.springframework.orm.jpa.JpaTransactionManager;
  import org.springframework.orm.jpa.JpaVendorAdapter;
  import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
  import org.springframework.transaction.PlatformTransactionManager;
  import org.springframework.transaction.annotation.EnableTransactionManagement;
  
  import javax.persistence.EntityManagerFactory;
  import javax.sql.DataSource;
  import java.util.Properties;
  
  @Configuration
  @ComponentScan(basePackages = {"ch.admin.estv.dvs.test.database"})
  @EnableTransactionManagement
  public class DvsTestDbConfig {
  
  
      @Value("${database.test}")
      String databaseTest;
  
      @Autowired
      private Environment environment;
  
      @Value("${database.driverClassName}")
      String driverClassName;
  
      @Value("${database.url}")
      String databaseUrl;
  
      @Value("${database.username}")
      String databaseUsername;
  
      @Value("${database.password}")
      String databasePassword;
  
  
      @Bean
      public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
          LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
          em.setDataSource(dataSource());
          em.setPackagesToScan(new String[]{"ch.admin.estv.dvs.test.database"});
          JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
          em.setJpaVendorAdapter(vendorAdapter);
          em.setJpaProperties(additionalProperties());
  
          return em;
      }
  
      @Bean
      public DataSource dataSource() {
          DriverManagerDataSource dataSource = new DriverManagerDataSource();
  
          System.out.println("**************  db property databaseTest : " + databaseTest);
  
          dataSource.setUrl(databaseUrl);
          dataSource.setUsername(databaseUsername);
          dataSource.setPassword(databasePassword);
          dataSource.setDriverClassName("oracle.jdbc.OracleDriver");
  
  
          return dataSource;
      }
  
      @Bean
      public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
          JpaTransactionManager transactionManager = new JpaTransactionManager();
          transactionManager.setEntityManagerFactory(emf);
  
          return transactionManager;
      }
  
      @Bean
      public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
          return new PersistenceExceptionTranslationPostProcessor();
      }
  
      Properties additionalProperties() {
          Properties properties = new Properties();
          //properties.setProperty("hibernate.hbm2ddl.auto", "validate");
          properties.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
  
          properties.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
          properties.setProperty("hibernate.jdbc.lob.non_contextual_creation", "true");
  
          properties.setProperty("show_sql", "true");
          return properties;
      }
  
  }
  </code></pre>
  
  <p>application.properties</p>
  
  <pre><code>database.test=qqqqqqqqq
  
  database.url=xxxxxxxxxxxxxxxxx
  database.username=xxxxxxxxxx
  database.password=xxxxxxxxxxx
  database.driverClassName=oracle.jdbc.OracleDriver
  </code></pre>
  
  <p>pom.xml</p>
  
  <pre><code>&lt;parent&gt;
      &lt;artifactId&gt;dvs-test&lt;/artifactId&gt;
      &lt;groupId&gt;ch.admin.estv.dvs&lt;/groupId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;/parent&gt;
  
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;artifactId&gt;dvs-test-database&lt;/artifactId&gt;
  &lt;packaging&gt;jar&lt;/packaging&gt;
  
  
  &lt;dependencies&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&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;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-oxm&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;javax.transaction&lt;/groupId&gt;
          &lt;artifactId&gt;javax.transaction-api&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.oracle&lt;/groupId&gt;
          &lt;artifactId&gt;ojdbc6&lt;/artifactId&gt;
          &lt;version&gt;${ojdbc6.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
  &lt;/dependencies&gt;
  </code></pre>
  
  <p></p>