In Gradle 4.6 release notes there was a statement:
Gradle now provides native support for JUnit Jupiter/Vintage Engine on top of JUnit Platform. To enable JUnit Platform support, you just need to add one line to your build.gradle:
test {
useJUnitPlatform()
}
So I tried to change my build.gradle to:
dependencies {
testCompile 'org.junit.jupiter:junit-jupiter-api'
}
test {
useJUnitPlatform()
}
However I’ve got exception:
:proj1:junitPlatformTestorg.junit.platform.commons.util.PreconditionViolationException: Cannot create Launcher without at least one TestEngine; consider adding an engine implementation JAR to the classpath
at org.junit.platform.commons.util.Preconditions.condition(Preconditions.java:297)
at org.junit.platform.launcher.core.DefaultLauncher.(DefaultLauncher.java:55)
It is not possible to run JUnit 5 tests without useJunitPlatform(). The default is the JUnit 4 framework. Maybe you previously used the org.junit.platform.gradle.plugin, which is different from the new built-in support.
That’s right. I used ‘org.junit.platform.gradle.plugin’ plugin for running JUnit 5 tests.
If I remove this plugin and switch to useJUnitPlatform() configuration for tests then tests are executed successfully.
However the need to add jupiter-engine dependency seems redundant to me as it’s default engine for running JUnit 5 tests.