Vertx(vertx-Junit5模块)未找到任何测试

时间:2018-02-22 14:14:31

标签: java junit vert.x junit5

我尝试在Vertx项目中实现Junit5。

只需添加junit5就可以了,但是在项目中添加了vertx-junit5模块,TestEngine在查找测试时遇到了问题

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

没有:

testCompile group: 'io.vertx', name: 'vertx-junit5', version: vertxVersion

测试引擎找到测试并且没有问题

但有这种依赖

  

未发现任何测试

     

2018年2月22日下午2:41:28 org.junit.platform.launcher.core.DefaultLauncher handleThrowable   WARNUNG:带有ID' junit-jupiter'的TestEngine未能发现测试   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)       在org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:61)       在org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:130)       在org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:117)       在org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:82)       at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:48)       在com.intellij.rt.execution.junit.IdeaTestRunner $ Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)       在com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)       在com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

     

2018年2月22日下午2:41:28 org.junit.platform.launcher.core.DefaultLauncher handleThrowable   WARNUNG:带有ID' junit-jupiter'的TestEngine未能发现测试   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)       在org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:61)       在org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:130)       在org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:117)       在org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)       at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:62)       在com.intellij.rt.execution.junit.IdeaTestRunner $ Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)       在com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)       在com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

     

进程以退出代码0结束   空测试套件。

我不明白为什么依赖会影响testEngine

我正在使用IntelliJ 2017.2.6

我尽可能简单地试试我的运气

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();
    }
}

2 个答案:

答案 0 :(得分:1)

也许您错过了测试类的JUnit5扩展注释:

DimshuffleLaye

答案 1 :(得分:0)

也许您应该在junitPlatform区块中提供更多配置(请参阅https://junit.org/junit5/docs/current/user-guide/#running-tests-build-gradle

使用Gradle时,我通常使用以下方式启用test任务:

junitPlatform { enableStandardTestTask true }

以下摘录自为我工作的build.gradle

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

希望它有所帮助!