SonarQube is not identifying code smells or bugs from src/test folder

I am using sonarqube withm java maven project. My project is created for automation test. I want to include src/test folder also for code analysis.
I have used following properties like:
sonar.projectKey=webautomation
sonar.sources=src/main/,src/test/
sonar.test.inclusions=src/test

But i am not seeing any code smells identified in report from the src/test folder which i deliberately introduced

Hi,

For most languages we only have a few rules (if any) that run on tests, and “normal” rules don’t run on them. To get issues raised on your tests, you’ll need to identify them as source code. That means this:

sonar.projectKey=webautomation
sonar.sources=src/main/*,src/test/*
sonar.test.inclusions=src/test

Be aware, though, that this configuration means unit test metrics may come out weird (since you “don’t have any tests”).

What some people have done in the past is run two different analyses, one “normal”, with the test files identified as test files & few if any issues raised on them. And then a second with the test files identified as sonar.sources.

 
Ann

1 Like

Hi Ann,
Thanks for answering the query.
I tried the suggested settings still it does not show any issues for src/test/* folder. Any other suggestions?
Thanks,
Chaithra

Hi,

I’m not sure where my head was when I recommended

But sonar.sources doesn’t accept wild cards. Can you try it again like this:

 
Thx,
Ann

Thanks Ann for the correction !!
Unfortunately this changes is also not providing any details for src/test folder. I am using Maven scanner. Am I missing out any details in property file, or any other setting that is resulting in this type of behaviour?
Thanks,
Chaithra

Hi Chaithra,

How are you setting those properties? Not in a sonar-project.properties file, I hope? The Maven scanner doesn’t read that file. You would need to set it on the analysis command line.

 
Ann

Oh! Thanks Ann, I was adding all these details in sonar-project.properties file.

Now I tried -Dsonar.sources=src/main,src/test along with maven goal sonar in commandline, While scanning for the java files under src/test folder it says " can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files ". Should I try to mention the source folder differently?

Chaithra

Hi Chathra,

Are you explicitly setting any inclusions?

Probably, though this is caused by sonar.tests being automatically set by Maven to src/test.

I was afraid of that. Unfortunately, I don’t think it works to set sonar.tests="" (i.e. empty string). You’ll have to point it at something explicit. Do you have directory you can use? Maybe the resources directory?

 
Ann

Thanks Ann, I tried changes as you mentioned like -Dsonar.sources=src/main,src/test/java -Dsonar.tests=src/test/resources. This actually worked for me.

Thanks again.

Chaithra

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.