How to set up build.gradle for JUnit5 in STS (Eclipse)

How to set up build.gradle for JUnit5 in STS (Eclipse)

JUnit5 is now the default in SpringBoot 2.2.

The default in build.gradle is as follows

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'
  }
}

If using JUnit 5.6, add the following two lines

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” is obsolete

As noted on the following site, the junit-platform-gradle-plugin has been deprecated.

It seems that all you have to do is declare useJUnitPlatform() in the test task.

JUnit 5 User Guide
test {
  useJUnitPlatform()
}

Other detailed test task properties are listed below.

Testing in Java & JVM projects

コメント

Discover more from 株式会社CONFRAGE ITソリューション事業部

Subscribe now to keep reading and get access to the full archive.

Continue reading

Copied title and URL