配置 Gradle 4.7 以生成 JUnit 5 测试的 HTML 报告

Configuration for Gradle 4.7 to generate the HTML report for JUnit 5 tests

我有一个基于以下内容的应用程序:

关于 Gradle 与 JUnit 的配置位于根模块的 build.gradle 文件中:

...
subprojects {

    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'org.junit.platform.gradle.plugin'

    sourceCompatibility = '1.8'
    targetCompatibility = '1.8'

    repositories {
        jcenter()
    }

    ext {
      ...
      junitVersion = '5.1.1'
      ...
    }

    dependencies {

       ...

       //Testing
       ...
       testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
       testCompile "org.junit.jupiter:junit-jupiter-params:$junitVersion";
       testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
       ....

    }

    test {
        useJUnitPlatform()      
    }

}

//This location is mandatory
buildscript {

    repositories {
        mavenCentral()
    }

    dependencies {      
        classpath "org.junit.platform:junit-platform-gradle-plugin:1.1.0"
    }

}

通过Jenkins我执行:

从以上所有工作正常,我可以在 Jenkins 中看到 @Test 已通过,但 Gradle 没有生成具有预期 htmlreport 目录] 文件。

即使直接在终端中执行 gradle :thymeleaf-02-infrastructure:test --parallel 命令,所有工作(测试通过),但 Gradle 不会生成具有预期 [=26] 的 report 目录=] 文件.

我已经阅读了这些链接:

而且我正在使用

test {
    useJUnitPlatform()      
}

Gradle>4.6,4.7,那么什么是不见了?

您需要删除 org.junit.platform.gradle.plugin,因为它默认禁用标准 test 任务。