Last active
February 24, 2023 06:51
-
-
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 ;)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great codes!! :-)