【问题标题】:integrate ant junit generated test-results in gradle html report在 gradle html 报告中集成 ant junit 生成的测试结果
【发布时间】:2014-01-31 19:32:13
【问题描述】:

在我的 gradle 构建脚本中,我添加了 doLast 方法来测试任务以运行 ant.junit 任务以从几个 jar 文件中执行测试。

    test <<  {
      //run ant junit task with reports stored in $buildDir/test-results

      //after ant junit completion and "test" task completion, 
      //how can I get the gradle generated html report include the above test-results?    
    }

如何增强此任务以获得 gradle html 报告的好处?我看到在 $buildDir/test-results 中正确创建了 ant junit 测试 xml 报告以及其他“gradle test”创建的 xml。但是 $buildDir/reports/tests" 仅包含。我希望 gradle 也会获取 ant junit 创建的测试结果 xml 文件并包含在其 html 报告中。但这没有发生。我怎样才能得到这种行为?

我尝试创建另一个 TestReport 类型的任务。但这也无济于事。

 task runTestsFromJar( type: TestReport ) {
        destinationDir=file("$buildDir/reports/tests")
        reportOn tasks.test, files("$buildDir/test-results/binary/test")
 }

我正在使用 gradle 1.8。

【问题讨论】:

    标签: gradle build.gradle


    【解决方案1】:

    我建议创建另一个 task of type Test 来替换您的 doAfter 闭包。

    task antTests(type: Test){
      //configuration here
    }
    

    我相信此时您可以使用与之前尝试类似的方式使用 TestReport 任务

    task runTestsFromJar( type: TestReport ) {
        destinationDir=file("$buildDir/reports/tests")
        reportOn test, antTests
    }
    

    我尝试根据现有 xml 结果文件的目录以及binary 子文件夹生成报告也失败了

    【讨论】:

    • 运气不好。它仍然不生成报告。我也尝试过使用 gradle 最新版本。
    • 您是否验证过 antTests 任务生成 XML junit 报告?
    • 另外,您之前的实现生成的测试输出是否包含 $buildDir/test-results/binary/test 中的 results.bin 文件,以便报告任务?
    • 是的。我验证了 xmls 存在。根据forums.gradle.org/gradle/topics/… 中提到的回复,显然这似乎不可行
    • 请查看我的project in GitHub。我认为 TestReport 任务使用的不是 XML 文件,而是嵌套的“二进制”文件夹中的 *.bin 文件。如果没有该目录中的 *.bin 文件,我无法使报告正常工作。当然,我在 src/rawResults 中报告的静态测试结果是从另一个 Gradle 项目生成的,而不是 Ant。
    【解决方案2】:

    根据gradle forum post 的回复,生成 gradle 样式的测试 html 报告似乎无法使用 gradle 开箱即用。 Gradle TestReport 任务似乎依赖于“测试”任务生成的二进制输出文件。当使用 gradle 中的 ant.JUnitTask 运行测试时,不会生成这些。 我最终求助于“ant JUnitReport task”来生成至少一个有意义的合并报告。

    test <<  {
      //run ant junit task with reports stored in $buildDir/test-results
    
      //after ant junit completion  
       ant.junitReport( toDir: "$buildDir/reports") {
                fileset ( dir:"$buildDir/test-results" )
                report ( format:"frames", todir:"$buildDir/reports" )
       }
    }
    

    这给出了一个基本的 html 报告。可以根据需要使用 XSLT 进行自定义。

    【讨论】:

    • 需要为junitreport添加任务定义:ant.taskdef(name: 'junitreport', classname: 'org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator', classpath: configurations.[configuration-containing ant-junit.jar].asPath )
    • 在此处查看示例:stackoverflow.com/a/39180709
    猜你喜欢
    • 2016-11-29
    • 2014-09-26
    • 2018-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-07
    相关资源
    最近更新 更多