Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save leonschreuder/c5e84ca21a768fd76a7d to your computer and use it in GitHub Desktop.
Save leonschreuder/c5e84ca21a768fd76a7d to your computer and use it in GitHub Desktop.
Gradle Robolectric commandline output formatting
//Add this to build.gradle
robolectric {
// Output and format the test results for vim-grand
afterTest { descriptor, result ->
//This part prints the class name with short result notation
def resultChar = ''
switch (result.resultType) {
case TestResult.ResultType.SUCCESS:
resultChar = '+'
break
case TestResult.ResultType.FAILURE:
resultChar = '-'
break
default:
resultChar = '?'
break
}
//Print time taken in ms
print "(" + ((result.getEndTime() - result.getStartTime()) / 1000) + "ms)\t"
println "$resultChar $descriptor.className > $descriptor.name"
//This prints a short stacktrace, ending with the assert description
if (result.resultType == TestResult.ResultType.FAILURE) {
result.getException().each {
it.getStackTrace().each { el ->
if (el.getFileName() && !(el.getClassName() =~
/^(java.lang|java.util|junit.framework|org.gradle|org.junit|sun.reflect)/)) {
println el.getFileName() + ":" + el.getLineNumber() + ":"
}
}
println it.toString()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment