0

The SONAR metrics include a section for evaluating the documentation quality, having an item Public undocumented API. This is very high in our project because it reports each and every unit test. However, unit test methods have to be public for Junit.

Is there an easy way to remove unit test methods from the undocumented API metric?

I'm aware of these alternatives:

  • We could add JavaDoc comments to each test method. This is not useful, as it just pollutes the code.
  • The tests are in Eclipse test fragment projects. We could completely exclude the test classes from the SONAR analysis. However, we generally want to have the same rules applied to test code and production code (e.g. when checking violations).

I have not found a section in the SONAR configuration matching that metric, but I may have missed it.

Bananeweizen
  • 21,797
  • 8
  • 68
  • 88
  • We have the same issue. We've used the pattern !*Test but that didn't help unfortunately. We are explicitly including our test files because we have rules that verify the qulaity of our test classes. e.g. test methods that lacks assertions. So I don't want to exclude the test classes as a whole. Did you find a solution for this yet? – BitfulByte May 11 '16 at 08:39

1 Answers1

1

This metric is not fed with unit test classes, you must have missed something in your configuration.

As an example, check out Sonar analysed by Sonar (on Nemo): you'll see that no test class is reported for the "public_undocumented_api".

  • Might this be caused by us not using the Maven standard directory layout? Instead of src/test/java our Test classes are in "src" (in separate Eclipse test plugin projects). This is basically the standard Eclipse source directory layout (for non Maven projects). – Bananeweizen Apr 18 '13 at 14:58
  • Yep, definitely! You can take a look at Sonar Eclipse code base to see how we configure everything so that it is analysed correctly by Sonar: https://github.com/SonarSource/sonar-eclipse – Fabrice - SonarSource Team Apr 18 '13 at 15:17