Question

In my gradle build script, I added doLast method to test task to run ant.junit task to execute tests from few jar files.

    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?    
    }

How do I enhance this task to get the gradle html report benefit? I see that ant junit test xml reports are properly getting created in $buildDir/test-results along with other "gradle test" created xmls. However $buildDir/reports/tests" contains only. I was hoping that gradle will pick up the ant junit created test result xml files as well and include in its html report. But this is not happening. How can I get this behaviour?

I tried to create another task of type TestReport. But it also did not help.

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

I am working with gradle 1.8.

Was it helpful?

Solution 2

Based on the response from gradle forum post, it seems generate gradle styled test html report is not available out-of-the box with gradle. Gradle TestReport task seems to be dependent on the binary output files generated by "test" task. These are not generated when the tests are run using ant.JUnitTask from gradle. I resorted to "ant JUnitReport task" finally to generate at least a meaningful consolidated report.

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" )
   }
}

This gives a basic html report. One can customize as needed using XSLT.

OTHER TIPS

I would suggest creating another task of type Test to replace your doAfter closure.

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

I believe at that point you can use the TestReport task in a similar manner as your previous attempt

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

My attempts to generate a report based on a directory of existing xml result files, and on the binary subfolder were unsuccessful as well

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top