Discussion:
Generating test reports from non-JUnit based tests
Robert Fletcher
2012-05-30 21:59:51 UTC
Permalink
Hi

I'm using Casper JS (http://casperjs.org/) to do some functional
testing. It generates a JUnit compatible XML report file. Is it
possible that I can get Gradle to parse the XML and generate shiny
HTML reports as for 'regular' JUnit/Spock tests?

What I'm doing currently is:

task testSite(type: Exec) {
commandLine 'casperjs', 'test', 'src/test/casper',
"--xunit=$testResultsDir/casper-suite.xml"
}

which is working fine but I just end up with XML. It looks like
Gradle's Test task type is purely geared up for executing JVM based
testing and there's not a way to run the report generation step in
isolation.

Thanks,
Rob
TheKaptain
2012-06-04 22:40:08 UTC
Permalink
Not sure if this is encouraged or not, but it works :)

task testSite(type: Exec) {
commandLine 'casperjs', 'test', 'src/test/casper',
"--xunit=$testResultsDir/casper-suite.xml"
doLast{
def reporter = new
org.gradle.api.internal.tasks.testing.junit.report.DefaultTestReport()
reporter.testResultsDir = file('path to result files from casper')
reporter.testReportDir = file('path to where you want the reports
written')
reporter.generateReport()
}
}


--
View this message in context: http://gradle.1045684.n5.nabble.com/Generating-test-reports-from-non-JUnit-based-tests-tp5709848p5709857.html
Sent from the gradle-user mailing list archive at Nabble.com.
Rob Fletcher
2012-06-06 12:23:45 UTC
Permalink
Thanks for the pointer. I found, however, that using doLast will only work so long as all the tests pass. With some help from Luke Daley I got this working by implementing a task listener:

task integrationTest(type: Exec) {
commandLine 'casperjs', 'test', '.', "--xunit=$testResultsDir/TEST-casper-suite.xml", '--ignore-ssl-errors=yes'
workingDir = 'src/test/casper'

gradle.addListener(new TaskExecutionListener() {
void beforeExecute(Task task) {}
void afterExecute(Task task, TaskState taskState) {
if (task.name == 'integrationTest') {
def reporter = new co.freeside.gradle.CasperTestReport()
reporter.testResultsDir = task.project.testResultsDir
reporter.testReportDir = task.project.testReportDir
reporter.generateReport()
}
}
})
}


As you can see I also had to implement my own TestReport class as the `DefaultTestReport` throws NPE as Casper doesn't generate timing information in its XML. Right now this means that if any Casper XML files are around when the regular `test` task runs then its own reporting will fail. I'm not sure if there's a way to override the `TestReporter` implementation that gradle's `test` task uses by default.

In an ideal world I should also get the Casper tests defined as a sourceSet, I guess.
--
Rob Fletcher
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
Post by TheKaptain
Not sure if this is encouraged or not, but it works :)
task testSite(type: Exec) {
commandLine 'casperjs', 'test', 'src/test/casper',
"--xunit=$testResultsDir/casper-suite.xml"
doLast{
def reporter = new
org.gradle.api.internal.tasks.testing.junit.report.DefaultTestReport()
reporter.testResultsDir = file('path to result files from casper')
reporter.testReportDir = file('path to where you want the reports
written')
reporter.generateReport()
}
}
--
View this message in context: http://gradle.1045684.n5.nabble.com/Generating-test-reports-from-non-JUnit-based-tests-tp5709848p5709857.html
Sent from the gradle-user mailing list archive at Nabble.com (http://Nabble.com).
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
TheKaptain
2012-06-06 22:45:00 UTC
Permalink
Glad it helped, and Luke is a very handy guy to have around, obviously :)

--
View this message in context: http://gradle.1045684.n5.nabble.com/Generating-test-reports-from-non-JUnit-based-tests-tp5709848p5709862.html
Sent from the gradle-user mailing list archive at Nabble.com.

Loading...