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

时间:2018-04-19 13:49:41

标签: gradle junit build.gradle junit5

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

  • Spring Framework 5.0.4.RELEASE
  • Gradle 4.7 - 通过
  • 配置的多模块项目
  • JUnit 5.1.1

关于Gradle with 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我执行:

  • gradle :thymeleaf-02-infrastructure:test --parallel
  • 并且Publish JUnit test result report配置为thymeleaf-02-infrastructure/build/test-results/junit-platform/*.xml

从上面所有工作都很好,我可以在Jenkins中看到@Test已通过但Gradle未生成report目录,其中包含预期的html文件。

即使直接在终端中执行gradle :thymeleaf-02-infrastructure:test --parallel命令,所有工作(测试过程),但Gradle都不会生成带有预期report的{​​{1}}目录文件。

我已经阅读了这些链接:

我正在使用

html

test { useJUnitPlatform() } > 4.6 4.7 ,那么缺少什么?

1 个答案:

答案 0 :(得分:3)

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

相关问题