Retrieve failed test file and line number

(Nathan) #1


I’d like to integrate Gradle with Vim when running tests. This would involve getting this standard output from running “gradle test”: > testMapper FAILED

java.lang.AssertionError at

into a file. I know how to get text into a file from a Gradle script, and I have found the afterTest and onOutput event hooks, but I cannot find the class/property that I need to reference in order to get the name of the file where test resides ( and the line number of the failure (45)

Can anyone point me to the class where I could retrieve this information from?

Thanks, --Nate

(Nathan) #2

I found an acceptible solution – the only thing I need to do is find out how to use Gradle’s Stack Trace Filter to remove the java.reflect, etc. Currently I’m just filtering hard-coded packages from the stack traces.

Try it out – the code’s on GitHub, with a project that’s ready to go. There’s a 2-liner bash script that runs gradle test, then opens Vim with the quickfix list pointing at the failed tests. You can then use Vim’s awesomeness to navigate the failed tests using :cn and :cp. Use :cope to open the Quickfix window that shows all the failed tests.

test {

delete ‘testresults’

def testresults = file(“testresults”)

include “**/Test*.class”

// The goal is to get something that Vim’s Quickfix can understand. Like this:

// Filename:LineNumber:FailureDescription

// null expected:<[b]ar> but was:<[B]ar>

afterTest { desc, result ->

if (result.resultType == TestResult.ResultType.FAILURE) {

result.getException().each {

it.getStackTrace().each { el ->

if (el.getFileName() && !(el.getClassName() =~


testresults << el.getFileName() + “:” + el.getLineNumber() + “:”



testresults << it.toString() + “\n”



} }