Reputation: 31
I tried to implement Junit5 in my Vertx Project.
Just adding junit5 works fine but with adding vertx-junit5 module to the project the TestEngine got problems finding the Tests
build.gradle:
buildscript {
repositories {
mavenCentral()
dependencies {
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.1.0'
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5"
}
}
}
plugins {
id'java'
id'application'
id'eclipse'
}
apply plugin: 'org.junit.platform.gradle.plugin'
apply plugin: 'maven'
apply plugin: "org.sonarqube"
def vertxVersion = "3.5.1"
version = 0.4
compileJava.options.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
dependencies {
compile "io.vertx:vertx-core:$vertxVersion"
compile "io.vertx:vertx-service-proxy:$vertxVersion"
compile "io.vertx:vertx-sockjs-service-proxy:$vertxVersion"
compile "io.vertx:vertx-hazelcast:$vertxVersion"
compile "io.vertx:vertx-web:$vertxVersion"
compile "io.vertx:vertx-config:$vertxVersion"
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.6'
testCompile group: 'io.vertx', name: 'vertx-unit', version: vertxVersion
testCompile group: 'io.vertx', name: 'vertx-junit5', version: vertxVersion
testCompile 'org.assertj:assertj-core:3.9.0'
//Junit 5
testCompile("org.junit.jupiter:junit-jupiter-api:5.1.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.1.0")
//Junit 5 vintage to run Junit4 Tests
testCompile("junit:junit:4.12")
testRuntime("org.junit.vintage:junit-vintage-engine:5.1.0")
compileOnly 'io.vertx:vertx-codegen:3.4.2'
}
whithout the :
testCompile group: 'io.vertx', name: 'vertx-junit5', version: vertxVersion
the Test Engine finds the Tests and make no Problems
but with this dependency
No tests were found
Feb 22, 2018 2:41:28 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable WARNUNG: TestEngine with ID 'junit-jupiter' failed to discover tests java.lang.NoSuchMethodError: org.junit.platform.engine.support.filter.ClasspathScanningSupport.buildClassFilter(Lorg/junit/platform/engine/EngineDiscoveryRequest;Ljava/util/function/Predicate;)Lorg/junit/platform/commons/util/ClassFilter; at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.resolveSelectors(DiscoverySelectorResolver.java:49) at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:61) at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:130) at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:117) at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:82) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:48) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Feb 22, 2018 2:41:28 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable WARNUNG: TestEngine with ID 'junit-jupiter' failed to discover tests java.lang.NoSuchMethodError: org.junit.platform.engine.support.filter.ClasspathScanningSupport.buildClassFilter(Lorg/junit/platform/engine/EngineDiscoveryRequest;Ljava/util/function/Predicate;)Lorg/junit/platform/commons/util/ClassFilter; at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.resolveSelectors(DiscoverySelectorResolver.java:49) at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:61) at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:130) at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:117) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:62) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Process finished with exit code 0 Empty test suite.
I dont understand why a dependency affects on the testEngine
Im using IntelliJ 2017.2.6
and I trying my luck with a Test simple as possible
import io.vertx.junit5.VertxTestContext;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
public class test {
@Test
@DisplayName("woop woooooooop")
void Test(){
VertxTestContext context = new VertxTestContext();
context.succeeding();
}
}
Upvotes: 2
Views: 1174
Reputation: 83
Maybe you miss JUnit5 extention annotation for your test class:
@ExtendWith(VertxExtension.class)
public class test {
...
}
Upvotes: 1
Reputation: 653
Perhaps you should provide more configuration in the junitPlatform
block (see https://junit.org/junit5/docs/current/user-guide/#running-tests-build-gradle)
When using Gradle I typically enable the test
task using:
junitPlatform {
enableStandardTestTask true
}
Here is an excerpt from a build.gradle
that works for me:
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.io.vertx:vertx-gradle-plugin:0.0.8"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.21"
classpath "org.junit.platform:junit-platform-gradle-plugin:1.0.3"
}
}
apply plugin: "io.vertx.vertx-plugin"
apply plugin: "org.jetbrains.kotlin.jvm"
apply plugin: "org.junit.platform.gradle.plugin"
repositories {
mavenCentral()
}
group 'io.github.jponge'
version '0.0.1-SNAPSHOT'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8"
compile "ch.qos.logback:logback-classic:1.2.3"
compile "io.vertx:vertx-web"
compile "io.vertx:vertx-lang-kotlin"
compile "io.github.jponge:vertx-boot:0.0.1"
testCompile "io.vertx:vertx-junit5"
testCompile "org.junit.jupiter:junit-jupiter-api:5.0.3"
testCompile "org.junit.jupiter:junit-jupiter-engine:5.0.3"
testCompile "org.apiguardian:apiguardian-api:1.0.0"
testCompile "org.junit.platform:junit-platform-launcher:1.0.3"
}
vertx {
vertxVersion = "3.5.1"
mainVerticle = "io.github.jponge.vertx.boot.BootVerticle"
}
junitPlatform {
enableStandardTestTask true
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
}
}
Hope it helps!
Upvotes: 0