STS(Eclipse)でJUnit5用のbuild.gradle設定方法

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

 

コメント

株式会社CONFRAGE ITソリューション事業部をもっと見る

今すぐ購読し、続きを読んで、すべてのアーカイブにアクセスしましょう。

続きを読む

タイトルとURLをコピーしました