[Sonar-Java] Filename matching for JUnit reports

576 views
Skip to first unread message

Peter van Zetten

unread,
Aug 25, 2016, 8:12:16 AM8/25/16
to SonarQube
Hi,

The Sonar-Java plugin offers the property sonar.junit.reportsPath to specify the path to JUnit XML reports. However the sensor providing the report matching is tightly bound to Surefire test output and will only match XML files beginning with "TEST-", a pattern which is not configurable[1], and is not mentioned in the doc for the parameter, which implies that `*.xml` will be accepted.

When not using Maven this can make it impossible to add test reports to the SQ analysis. For example buck's java_test goal generates files named like .../com.example.TestClass.xml but I don't think it's possible to process them.

Is there any way to configure the filename pattern that I've missed?

Thanks in advance!

[1]: https://github.com/SonarSource/sonar-java/blob/master/java-surefire/src/main/java/org/sonar/plugins/surefire/SurefireJavaParser.java#L76

Nicolas Peru

unread,
Aug 26, 2016, 3:21:57 AM8/26/16
to Peter van Zetten, SonarQube
Hi Peter, 

First a small disclaimer : I know nothing about buck. 
So before asking anything about how to configure a file name etc... : what is the format of those test output ? can it be parsed like surefire reports ? (cf the schema mentioned here : http://maven.apache.org/surefire/maven-surefire-plugin/ (direct link to schema)
So I am not sure that by making the filename configurable it will solve your usecase.

Cheers, 





--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/78c9670e-d675-4bd3-b8f6-0f415f6419f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Nicolas PERU | SonarSource
Senior Developer
http://sonarsource.com

Peter van Zetten

unread,
Aug 26, 2016, 5:07:46 AM8/26/16
to SonarQube, peter.v...@gmail.com
Hi Nicolas,

You know, I was just blindly trusting that the format was the same, but on closer inspection I see now that buck is producing the report according to its own general language-independent test report schema (https://github.com/facebook/buck/issues/143). :(

So my particular problem won't be solved unless I do some transformation first - fortunately it seems someone has written XSLT to do just that, and I guess I can rename them to TEST-foo.xml along the way.

But to continue regardless... I think the 'Surefire' schema actually originated back in Ant (https://ant.apache.org/manual/Tasks/junitreport.html), and it does seem to be a widely-adopted convention for JUnit and general test reports, e.g. gtest for C++ tests will use this schema when asked to output xml, but with no fixed filename pattern. Jenkins JUnit plugin will also parse these files (manually via dom4j) but it allows you to configure the reports path, e.g. "**/TEST-*.xml".

So overall I still think in principle it might be nice for Sonar-Java to allow customisable filename patterns, or at least to make the hardcoded pattern/Surefire limitation clear in the doc for the reportsPath parameter. That way I could at least have hit parser errors rather than a mysterious "no reports found" :)
Reply all
Reply to author
Forward
0 new messages