title: spring boot unit test active profiles
body: <p>spring boot <code>main</code> uses <code>mysql</code> in <code>application.properties</code> and <code>test</code> uses <code>h2</code> in <code>application-ut.properties</code>. However, when run tests, in console it says <code>active profile: ut</code>, but <code>test</code> still uses <code>datasource application.properties</code>. And once I remove <code>application.properties</code> tests would use <code>h2</code>. </p>
  
  <p><strong>Test</strong>:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  @AutoConfigureMockMvc
  @ActiveProfiles(value = "ut")
  </code></pre>
  
  <p><strong>POM:</strong></p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;com.h2database&lt;/groupId&gt;
      &lt;artifactId&gt;h2&lt;/artifactId&gt;
      &lt;scope&gt;test&lt;/scope&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p><strong>application-ut.properties:</strong></p>
  
  <pre><code>app.name=My app.
  server.context-path=/
  spring.jackson.serialization.indent-output=true
  spring.jpa.hibernate.ddl-auto=create
  spring.jpa.generate-ddl=true
  </code></pre>
  
  <p><strong>application.properites:</strong></p>
  
  <pre><code>app.name=my app
  server.context-path=/
  spring.jackson.serialization.indent-output=true
  spring.datasource.url=jdbc:mysql://localhost:3306/myapp
  spring.datasource.username=
  spring.datasource.password=
  spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  spring.jpa.hibernate.ddl-auto=update
  spring.jpa.generate-ddl=true
  </code></pre>
  
  <p><strong>Console</strong>:</p>
  
  <pre><code>10:03:37.570 [main] INFO  com.example.demo.RestControllerTest 641 logStartupProfileInfo  - The following profiles are active: ut
  10:03:37.726 [main] INFO  org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext 582 prepareRefresh  - Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6b53bcc2: startup date [Fri Jun 23 10:03:37 CST 2017]; root of context hierarchy
  10:03:37.804 [background-preinit] INFO  org.hibernate.validator.internal.util.Version 30 &lt;clinit&gt;  - HV000001: Hibernate Validator 5.3.4.Final
  10:03:38.225 [main] INFO  org.springframework.data.repository.config.RepositoryConfigurationDelegate 165 multipleStoresDetected  - Multiple Spring Data modules found, entering strict repository configuration mode!
  **[And then it loads datasource in application.properties]**
  </code></pre>