Retrieve failed test file and line number

Hello,

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

hadoop.dev.api.mrunit.TestWordCount > testMapper FAILED

java.lang.AssertionError at TestWordCount.java:45

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 (TestWordCount.java) and the line number of the failure (45)

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

Thanks, --Nate

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.

https://github.com/NathanNeff/gradle-examples/tree/master/testwithvim

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

// TestFoo.java:19:junit.framework.ComparisonFailure: 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() =~

/^(java.lang|java.util|junit.framework|org.gradle|org.junit|sun.reflect)/))

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

}

}

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

}

}

} }