私が設定したのGradleとの統合テストをして利用したいSpringの「プロパティの継承を」。しかしapplication.properties
からはmain
完全に置き換えられます。
ディレクトリ構造:
src/
intTest/
kotlin/my/package/
SomethingTest.kt
resources/
application.properties
main/
kotlin/my/package/
Something.kt
resources/
application.properties
その理由は、私が使用していることが考えられますapplication.properties
に(同じファイル名を持つ)intTest
としてmain
ディレクトリ。私は、レッツ・コール、それは「intTest」と呼ばれるファイルをプロファイルを使用している場合しかし、application-intTest.properties
それはどちらか動作しません。プロファイルの特定のファイルがすべてでピックアップされていません。
Gradleの設定:
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
(JUnitの5に基づいて)テストクラスを用いて注釈されています。
@ExtendWith(SpringExtension::class)
@ComponentScan
@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
私が追加した場合@TestPropertySource
、私のテストクラスにプロパティファイルには、少なくともピックアップされています。
@TestPropertySource(locations= ["classpath:application-intTest.properties"])
しかし、「プロパティの継承は、」どちらか動作しません。それは基本的に使用するのと同じであるので、application.properties
(プロファイルの一部なし)、何からすべてのプロパティをオーバーライドしますmain
。
追加@Profile("intTest")
私のテストには、問題を解決していません。同じことが当てはまるのために@ActiveProfiles("intTest")
。
どのように私は統合テストのセットアップで「プロパティの継承」を使用することができますか?
これは、問題は私のGradleの設定が、私のIntelliJの設定ではなかったことが判明しました。すなわち、各統合テスト・フォルダ内のすべての実行構成のために-アクティブなプロファイルは、実行コンフィギュレーションに設定する必要があります。これは、との統合テストクラスに注釈を付けることによって解決することができます@ActiveProfiles("intTest")
。