Created
October 24, 2018 07:13
-
-
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
This file contains hidden or 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() { | |
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