GradleプロジェクトでJUnit5を使う – 【Java】
GradleプロジェクトでJUnit5を使うには、build.gradreを以下のようにしたら動きました。
どうやら、junit-jupiter~系のバージョンとjunit-platform-launcherのバージョンによっては上手くJUnit5のテストが出来ないようです。
plugins {
id 'java-library'
}
repositories {
jcenter()
}
test {
useJUnitPlatform {
includeTags 'fast'
excludeTags 'slow'
}
}
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:28.0-jre'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.5.2'
testImplementation 'org.junit.platform:junit-platform-launcher:1.5.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
}
| ライブラリ | バージョン |
|---|---|
| junit-jupiter-api | 5.5.2 |
| junit-jupiter-params | 5.5.2 |
| junit-jupiter-engine | 5.5.2 |
| junit-platform-launcher | 1.5.2 |
バージョン指定
JUnit5のバージョン指定するには、build.gradleに以下1行追加します。
ext['junit-jupiter.version'] = '5.10.0'
spring-boot-starter-testにJUnit Jupiter,mockito,AssertJなどが含まれているようです。
testImplementation ('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
参考サイト
JUnit 5 User Guide
Testing in Java & JVM projects

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


コメント