Adding specific dependencies solve the problem.
NOTE: UPDATE INTELLIJ ABOVE 2017.2.0 AS THERE WAS A BUG WITH THE JUNIT LAUNCHER
OXYGEN if you using eclipse.
Below dependency enables Junit5 parametrized tests which can be used instead of a DataProvider.
"org.junit.jupiter:junit-jupiter-params:5.0.0"
//for JUnit5 parametrized tests.
Junit5 API.
"org.junit.jupiter:junit-jupiter-api:5.0.0"
//JUnit5 API
Needed if you want to run legacy JUnit4 tests without changing the syntax and imports.
"org.junit.vintage:junit-vintage-engine:4:12.0"
//for legacy JUnit4 tests
EDIT: 07/2018 Match the version of the vintage runner to the jupiter version
Needed if you want to run JUnit5 tests with new syntax and imports.
"org.junit.jupiter:junit-jupiter-engine:5.0.0"
//for JUnit5 tests
java.lang.NoSuchMethodError: org.junit.platform.engine.EngineDiscoveryRequest.getDiscoveryFiltersByType(Ljava/lang/Class;)Ljava/util/List;
Launcher.
"org.junit.platform:junit-platform-launcher:1.0.0
//to handle default launcher
Exception in thread “main” java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader;
Additional info how to install JUnit5
Since version 4.6 for Gradle, there is no need for plugins anymore
Gradle supports Junit5 natively just do:
And the version of the vintage runner is now same as the JUnit 5 version.
dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
}
test {
useJUnitPlatform {
includeEngines 'junit-jupiter', 'junit-vintage'
}
}