STS(Eclipse)でJUnit5用のbuild.gradle設定方法
SpringBoot2.2でJUnit5がデフォルトになりました。
build.gradleのデフォルトは以下のようになっています。
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
JUnit5.6を使う場合は以下の1行を追加します。
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
ext['junit-jupiter.version'] = '5.6.0'
junit-platform-gradle-pluginが廃止
以下サイトに記載がある通り、junit-platform-gradle-pluginが廃止になりました。
testタスクにuseJUnitPlatform()を宣言すればJUnit5を使う事になります。
JUnit 5 User Guide
test {
useJUnitPlatform()
}
もしくはtestタスクを拡張します。
tasks.named('test') {
useJUnitPlatform()
}
その他詳細なtestタスクのプロパティが以下に記載されています。
Testing in Java & JVM projects
参考サイト
JUnit 5 User Guide
Testing in Java & JVM projects

KHI入社して退社。今はCONFRAGEで正社員です。関西で140-170/80~120万から受け付けております^^
得意技はJS(ES20xx),Java,AWSの大体のリソースです
コメントはやさしくお願いいたします^^
座右の銘は、「狭き門より入れ」「願わくは、我に七難八苦を与えたまえ」です^^


コメント