TestCase analysis- Want to exclude code smells/issues on Test Case projects in sonar

I have a C# API solution which is having code project and a test project. I am using classic azure CICD pipeline. Help me to set up sonarqube to get code coverage and code smell . Also I don’t want test project files should be part of code smell. it only should be part of code coverage.

Our current pipeline task setup given below:

PrepareAnalysis- Dotnet Restore- Test Case Analysis using dot net task- Dotnet Publish- Run Code Analysis

Sonar property we tried out in pipelines not working:

sonar.issue.ignore.multicriteria=e1
sonar.issue.ignore.multicriteria.e1.resourceKey=myAPI/myAPITest.Tests/**/.cs
sonar*.issue.ignore.multicriteria.e1.ruleKey=**

Pipelines running successfully but still test case projects showing code smell issues in dashboard.

Pipeline logs for sonar scan.txt (183.4 KB)

We are using comminity edition of sonarqube with 10.6 version.

Thanks,

Muhammadh.

Hi Muhammadh,

Specifying multi-part properties is ticklish via text. Can you try 2 changes

  • move this into the UI
  • use a ruleKey of csharpsquid:* or of just *. But ** is a glob pattern that excludes multiple directories and is not appropriate here.

Once we’ve got the pattern nailed down, then you can work on moving it back into your properties if you like.

 
Thx,
Ann

Hi Ann,

Thanks for your update. We have tried both this property(use a ruleKey of csharpsquid:* or of just *) in sonar UI for the project we are trying to analyze. But still it is not working and issues are flagged out for the test case projects we don’t require to publish in sonar dashboard.

Kindly help. We want to get the code coverage by doing test case analysis in pipeline at the same time we want to suppress the vulnerabilities raised for the test case files on sonar UI.

Pipeline sonar.properties setting:

sonar.projectName=AssignmentAPI2
sonar.host.url=https://myispsonarqube.ciostage.accenture.com
sonar.verbose=true

Pipeline logs: Please see the attachements.

Rulekeypatternexclude_csharsquid.txt (3.4 KB)

Pipeline logs for all rule key pattern exclusion.txt (3.3 KB)

Thanks,

Muhammadh

Hi Muhammadh,

The logs you’ve provided aren’t adequate. I may need to ask you for the full files, redacted as necessary. First though, the reason you include tests in your analysis at all is that you want to make sure coverage shows up correctly on your non-test files? You think that without the tests visible to analysis to back up the coverage data, the coverage data won’t be imported or interpreted correctly? Because I don’t believe that’s the case. Can you try excluding your test project from analysis?

 
Ann