Skip to content

Instantly share code, notes, and snippets.

@eric100lin
Created October 24, 2018 07:13
Show Gist options
  • Save eric100lin/7059be7d6fff9e9065a2a1acadb6b01d to your computer and use it in GitHub Desktop.
Save eric100lin/7059be7d6fff9e9065a2a1acadb6b01d to your computer and use it in GitHub Desktop.
Gradle task to parse xml of Android JUnit test result(connectedAndroidTest) and generate a csv with mapping owner
task collectResults() {
doLast {
def ownerTable = new XmlSlurper().parse(file("owners.xml"))
def output = file("summary.csv")
output.text = '"Owner","Result","Test","Duration","Command"\r\n'
allprojects.each { project_x ->
println "Processing project ${project_x.name}"
def resultFiles = project_x.fileTree("build") { include '**/TEST-*.xml' }
resultFiles.each { file ->
println "Processing report ${file}"
def testsuite = new XmlSlurper().parse(file)
testsuite.testcase.each { testcase ->
def owner = "default-owner"
ownerTable.mapping.any { mapping_x ->
if ("${testcase.@classname}".matches("${mapping_x.package}")) {
owner = mapping_x.owner
return true // break
}
}
def result = "pass"
if (!testcase.failure.isEmpty()) { result = "fail" }
else if (!testcase.skipped.isEmpty()) { result = "skip" }
output << "\"${owner}\",\"${result}\",\"${testcase.@classname}#${testcase.@name}\",\"${testcase.@time}\","
output << "\"gradlew.bat connectedAndroidTest --continue -Pandroid.testInstrumentationRunnerArguments.class=${testcase.@classname}#${testcase.@name}\"\r\n"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment