What is the real purpose of sonar.tests properties?

What is the real purpose of these properties:

  • sonar.tests
  • sonar.tests.inclusions
  • sonar.tests.exclusions

No where in sonarqube’s documentation is clearly explained what these properties really mean. In the page Analysis Parameters | SonarQube Docs it says

What does that mean? What actually happens if someone passes or does not pass the sonar.tests property? Is this a redundant property if I pass sonar.exclusions and sonar.coverage.exclusions property as well?

Can someone please explain the use of these 3 properties like I’m a 5 year old and can someone please help update the official documentation too? The official documentation also does not even mention anything about sonar.coverage.exclusions property.

I will be happy to volunteer and contribute to the documentation if needed.


sonar.sources and sonar.tests are two properties used to define where are your main/business source files and where are your test files in your project.

If you do nothing, by default with the SonarScanner CLI, all source files of your project will be considered as “main” and the specific rules that run on test files won’t be executed.
When you are using the SonarScanner for Maven or Gradle, you have most of the time nothing to do because sonar.sources and sonar.tests are set automatically.

The “inclusions” and “exclusions” properties, are used to fine tune what you want or don’t want to be part of the scope of your scan.
You have:

  • sonar.inclusions + sonar.exclusions to be used for your main code (see documentation: Narrowing the Focus | SonarQube Docs)
  • sonar.test.inclusions + sonar.test.exclusions to be used to fine tune the scope of test files to be part of your scan (see documentation of SonarCloud that is more precise than the one of SonarQube for test files: Analysis Scope | SonarCloud Docs)

Warning: there is a typo in the property names you shared, there is no “s” at the end of “sonar.test.xxx”, it’s sonar.test.inclusions and sonar.test.exclusions. I know it’s boring to have such inconsistency in property names, hopefully, we will fix that one day.



Can u elaborate on the available rules ? can u list it or provide the link ?

1 Like

Agree. What rules are applied?
It is still not clear what happens when you pass sonar.tests and sonar.test.inclusions?

@Alexandre_Gigleux Please tell us the effect of doing this.

Sorry, I can’t answer that question.

Hi @Abhijeet_Vaikar. We completely rewrote the Analysis Parameters (formerly Narrowing the Focus) page since this thread was last active. Do these examples help?

  • scroll down to the 4th and 5th examples to see the sonar.tests and sonar.test.inclusions diagrams.

If the diagrams and new text don’t help, I’d like feedback on where we can improve.

1 Like