Create a gist now

Instantly share code, notes, and snippets.

Using Gradle & ANT to get JUnit XML results (e.g. from Jasmine) in HTML
configurations {
jasmineXmlToHtml
}
dependencies {
jasmineXmlToHtml 'org.apache.ant:ant-junit:1.8.2'
}
task jasmine(type: Exec) {
workingDir = 'src/test'
runnerFile = new File(workingDir, 'lib/phantomjs-testrunner.js')
specRunnerFile = 'file:///' + new File(workingDir, 'SpecRunner.html').absolutePath.replaceAll('\\\\', "/")
resultsDir = new File(buildDir, 'reports/jasmine')
commandLine = ['phantomjs', runnerFile, specRunnerFile]
doLast {
convertJasmineXmlToHtml(resultsDir)
}
}
def convertJasmineXmlToHtml(resultsDir) {
targetDir = new File(resultsDir, 'html')
ant.taskdef(
name: 'junitreport',
classname: 'org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator',
classpath: configurations.jasmineXmlToHtml.asPath
)
ant.junitreport(todir: resultsDir) {
fileset(dir: resultsDir, includes: 'TEST-*.xml')
report(todir: targetDir, format: "frames")
}
}
<!DOCTYPE html>
<html>
<head>
<title>Jasmine Spec Runner</title>
<link rel="stylesheet" type="text/css" href="../lib/jasmine-1.1.0/jasmine.css">
<script type="text/javascript" src="../lib/jasmine-1.1.0/jasmine.js"></script>
<script type="text/javascript" src="../lib/jasmine.junit_reporter.js"></script>
</head>
<script type="text/javascript">
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter('../../build/reports/jasmine/', false)); // don't consolidate so that JUnitReport can pick up the XML
jasmine.getEnv().execute();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment