使用TestReport聚合gradle多项目测试结果

n4r*_*zul 15 automated-tests build gradle

我的项目结构如下所示.我想在Gradle中使用TestReport功能将所有测试结果聚合到一个目录中.然后,我可以通过单个index.html文件访问所有子项目的所有测试结果.我怎么能做到这一点?

.
|--ProjectA
  |--src/test/...
  |--build
    |--reports
      |--tests
        |--index.html (testresults)
        |--..
        |--..
|--ProjectB
    |--src/test/...
      |--build
        |--reports
          |--tests
            |--index.html (testresults)
            |--..
            |--..
Run Code Online (Sandbox Code Playgroud)

Pet*_*ser 29

来自例23.13.Gradle用户指南中为子项目创建单元测试报告:

subprojects {
    apply plugin: 'java'

    // Disable the test report for the individual test task
    test {
        reports.html.enabled = false
    }
}

task testReport(type: TestReport) {
    destinationDir = file("$buildDir/reports/allTests")
    // Include the results from the `test` task in all subprojects
    reportOn subprojects*.test
}
Run Code Online (Sandbox Code Playgroud)

完全工作的样品可从samples/testing/testReport完整的Gradle分布中获得.

  • 它只是被弃用的`test.testReport`属性.正如弃用消息所示,您只需要用`test.reports.html.enabled = false`替换它. (3认同)
  • 我发现如果一个测试失败,任务报告没有完成 - 其他测试都没有执行,所以需要将`ignoreFailures`添加到`test`任务([source](https://discuss.gradle).组织/吨/ gradle这个-IF-junits失效最集结是不尽的,而无需执行的最下一测试用例/7分之6868)). (3认同)