首页 文章

在gradle html报告中集成ant junit生成的测试结果

提问于
浏览
0

在我的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报告的好处?我看到ant junit test xml报告正在$ buildDir / test-results中与其他“gradle test”创建的xmls一起正确创建 . 但是$ 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 .

2 回答

  • 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 子文件夹上也未成功

  • 1

    基于来自gradle forum post的响应,似乎生成gradle样式的测试html报告不具备开箱即用的gradle . Gradle TestReport任务似乎依赖于"test"任务生成的二进制输出文件 . 使用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进行自定义 .

相关问题