Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using sonar.test.exclusions with Sonarqube 6.3

Tags:

sonarqube

I'm currently evaluating Sonarqube 6.3 (a big upgrade from my current 5.5 instance) and I'm getting confused trying to work out the functionality of the sonar.test.exclusions setting.

There's this question: Sonar Maven Plugin: How do I exclude test source directories? which seems to indicate that it is used to exclude test files from analysis (which is what I'm after - I don't want my sonar ruleset run over my unit tests). The documentation https://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus also indicates that it is used to 'exclude unit test files' (perhaps this can be expanded upon to make it clearer?)

Thing is, when I add sonar.test.exclusions with a value of **/src/test/** and then run my analysis, I'm still getting code smells and the like being found for:

  • Foo/src/test/java/foo/bar/BarTest.java
  • Foo/src/test/java/lah/LahTest.java

etc.

When I use sonar.exclusions instead, they don't show up. Why is sonar.test.exclusions not doing what I expect?

like image 245
f1dave Avatar asked Apr 03 '17 03:04

f1dave


Video Answer


1 Answers

First of all: if you have a Maven project, you should use the scanner for Maven (mvn sonar:sonar). It will simplify your configuration, and will automatically register src/test/java folder as a test directory.

Now if you want to do the configuration manually, or understand what is going on under the hood, here is the explanation: SonarQube scanner work with 2 sets of files, main and test. Main source files are configured using the property sonar.sources. Test source files are configured using sonar.tests.

On top of that, you can filter some content using the sonar.[test.]exclusions properties.

In you case your problem is that Foo/src/test/java/foo/bar/BarTest.java seems to be considered as a main source file. That's why sonar.test.exclusions has no effect.

like image 123
Julien H. - SonarSource Team Avatar answered Jan 01 '23 08:01

Julien H. - SonarSource Team