Test XML report with test class annotation

We have big amount test classes. Each test has owner, team, area, etc. These information are in annotation at the class level. For subsequent processing test results I need these information.

How can I get these information into the XML report?

The ideal would be create elements property for each information, see: JUnit.xsd

Thank you

In my understanding, your goal is

  1. generate customized JUnit XML.
  2. classify tests

1.generating customized JUnit XML

Currently there is no way to insert information into JUnit XML.

But tests information is available via TestListener which can be added via Test#addTestListener(TestListener), or via Test#afterTest(Closure) whose arguments are TestDescriptor and TestResult.

Using TestDescriptor and TestResult, you can create JUnit xml…

afterSuite {TestDescriptor desc, TestResult res ->
    def xmlFile = file("${testResultDirName}/sample/reports/${desc.className}-${desc.name}.xml")
    def sw = new StringWriter()
    def xml = new MarkupBuilder(sw)
    xml.mkp.xmlDeclaration(version: '1.0', encoding: 'UTF-8')
    xml.testsuite(name: desc.className,
            tests: res.testCount,
            skipped: res.skippedTestCount,
            failures: res.failedTestCount,
            errors: res.exceptions.size(),
            timestamp: new Date(res.endTime)) {
        'properties' (value: 'your-favorite-value')
        testcase(name: desc.name, classname: desc.className, time: (res.endTime - res.startTime)/1000)
    }
    xmlFile.write(sw.toString(), 'UTF-8')
}

2. classify tests

  1. Add @Category annotation to your test classes.
  2. Divide test tasks via @Category using Test#useJUnit
  3. Each of test tasks, apply customized JUnit XML generation mentioned before.

Thanks for answer,
but in TestDescriptor missing information about class annotation.

I found on git hub great solution: GRADLE-2895 - Add support for user defined JUnit RunListeners. That’s exactly what I am looking. Unfortunately, this change isn’t merge to gradle master branch.

It is possible to finish this merge? What is need for finishing this issue?

Hi

Did you ever managed to implement this?
I would also love to be able to annotate my JUnit tests with e.g requirement number and get those numbers into the HTML report.