title: How to override application.properties in Spring Boot integration test?
body: <p>I've set up <a href="https://docs.gradle.org/current/userguide/java_testing.html#sec:configuring_java_integration_tests" rel="nofollow noreferrer">integration tests with Gradle</a> and want to use <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html" rel="nofollow noreferrer">Spring's "property inheritance"</a>. But the <code>application.properties</code> from <code>main</code> gets completely replaced.</p>
  
  <p>Directory structure:</p>
  
  <pre><code>src/
    intTest/
      kotlin/my/package/
        SomethingTest.kt
      resources/
        application.properties
    main/
      kotlin/my/package/
        Something.kt
      resources/
        application.properties
  </code></pre>
  
  <p>The reason could be that I'm using <code>application.properties</code> (with the same file name) in the <code>intTest</code> <em>and</em> in the <code>main</code> directory. However, if I'm using a profile, let's call it "intTest" and a file called <code>application-intTest.properties</code>, it doesn't work either. The profile specific file is not picked up at all.</p>
  
  <p>Gradle config:</p>
  
  <pre><code>sourceSets {
      intTest {
          compileClasspath += sourceSets.main.output
          runtimeClasspath += sourceSets.main.output
      }
  }
  
  configurations {
      intTestImplementation.extendsFrom testImplementation
      intTestRuntimeOnly.extendsFrom runtimeOnly
  }
  
  task integrationTest(type: Test) {
      description = 'Runs integration tests.'
      group = 'verification'
      useJUnitPlatform()
      systemProperty 'spring.profiles.active', 'intTest'
      testClassesDirs = sourceSets.intTest.output.classesDirs
      classpath = sourceSets.intTest.runtimeClasspath
      shouldRunAfter test
  }
  
  check.dependsOn integrationTest
  </code></pre>
  
  <p>The test class (based on JUnit 5) is annotated with: </p>
  
  <pre><code>@ExtendWith(SpringExtension::class)
  @ComponentScan
  @DataJpaTest
  @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
  </code></pre>
  
  <p>If I add <code>@TestPropertySource</code> to my test class the properties file is at least picked up:</p>
  
  <pre><code>@TestPropertySource(locations= ["classpath:application-intTest.properties"])
  </code></pre>
  
  <p>But the "properties inheritance" doesn't work either. So it is basically the same as using <code>application.properties</code> (without a profile part), what overrides all properties from <code>main</code>.</p>
  
  <p>Adding <code>@Profile("intTest")</code> to my test doesn't solve the problem. The same applies for <code>@ActiveProfiles("intTest")</code>.</p>
  
  <p>How can I use "properties inheritance" with my integration test setup?</p>