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を使う場合は以下の2行を追加します。

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'
  }
  testImplementation('org.junit.jupiter:junit-jupiter-api:5.6.0')
  testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine:5.6.0')
}

junit-platform-gradle-pluginが廃止

以下サイトに記載がある通り、junit-platform-gradle-pluginが廃止になりました。

testタスクにuseJUnitPlatform()を宣言すればよいだけのようです。

JUnit 5 User Guide
test {
  useJUnitPlatform()
}

その他詳細なtestタスクのプロパティが以下に記載されています。

Testing in Java & JVM projects

コメント

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