I am migrating an ant build to a gradle build.
Currently we use annotated test methods and a custom Junit formatter to out the annotation information into the xml junit output. Then using a customised xslt file we can generate a HTML report that includes information from the annotations in the test classes.
As there is no way to add the equivalent in gradle, I have been looking into using the testListener interface to output the same information (but it does not need to be a HTML report equivalent, I am happy to start with creating a simple text file).
So in the test.afterTest closure I can get the test class name from testDescriptor.parent.name, but Class.forName will throws a ClassNotFound exception.
The source sets api does not supply access to the classes so this appears to be a dead end.
How can I get this code to work:
test.afterTest { TestDescriptor testDescriptor, TestResult result ->
def testClass = Class.forName(testDescriptor.parent.name) // throws ClassNotFoundException!!!
def testMethod = testClass.getMethods().find{it.equals(testDescriptor.name)}
testMethod.declaredAnnotations.each {
// do something with the annotation here to output information.....
}
}