Last active
August 29, 2015 14:15
-
-
Save leonschreuder/c5e84ca21a768fd76a7d to your computer and use it in GitHub Desktop.
Gradle Robolectric commandline output formatting
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
//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