Skip to content

Instantly share code, notes, and snippets.

@double16
Last active February 24, 2023 06:51
Show Gist options
  • Save double16/654c2146bacc0e49ac9d to your computer and use it in GitHub Desktop.
Save double16/654c2146bacc0e49ac9d to your computer and use it in GitHub Desktop.
Gradle task to collect JUnit test results into a CSV, makes your manager happier, they like Excel ;)
task collectResults() {
def output = file("build/reports/summary.csv")
doLast {
file("build/reports").mkdirs()
output.text = '"Project","Test","Time","Result","Duration"\r\n'
allprojects.each { project2 ->
logger.info("Processing project ${project2.name}")
def resultFiles = project2.fileTree("build") { include '**/TEST-*.xml' }
resultFiles.each { file ->
logger.info("Processing report ${file}")
def testsuite = new XmlSlurper().parse(file)
testsuite.testcase.each { testcase ->
def result = "pass"
if (!testcase.failure.isEmpty()) { result = "fail" }
else if (!testcase.skipped.isEmpty()) { result = "skip" }
output << "\"${project2.name}\",\"${testcase.@classname}.${testcase.@name}\",\"${testcase.@timestamp}\",\"${result}\",\"${testcase.@time}\"\r\n"
}
}
}
}
}
@eric100lin
Copy link

Great codes!! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment