Sonarcloud old unit test code smell reappearing in new code analysis

We use sonar cloud for our project code quality analysis. We are facing one problem very frequently now-a-days. When we check in any code, the unit test code analysis for the whole project is being triggered and coming as new code analysis outcome. E.g. I have abc.cs, def.cs, ghi.cs, xyzunittest.cs files in the branch. I updated only abc.cs file and checked in. I see the code analysis has new code smells in xyzunittest.cs. Did you hear about this issue before or have any clue why it might happen?

  • Versions used (SonarQube, Scanner, Plugin, and any relevant extension)
    We use Sonarcloud. Azure DevOps Task (Scanner and Analysis) versions: 4
  • Error observed (wrap logs/code around triple quote ``` for proper formatting)
  • Steps to reproduce: Trigger one sonar cloud build
  • Potential workaround: exclude the unit test files from analysis
  • Scanner command used when applicable (private details masked)
    sonar.exclusions=/AssemblyInfo.cs
    sonar.test.exclusions=
    /AssemblyInfo.cs
    sonar.cs.vstest.reportsPaths=$(BUILD.SOURCESDIRECTORY)\Sources\TestResults**\TestResults*.trx
  • In case of SonarCloud:
    • ALM used (Azure DevOps)
    • CI system used (Azure DevOps)

Hey there.

It’s a bit hard to understand the problem from your description. How about some screenshots, or a public sample project on SonarCloud that display the issue?

Hi Colin,
Not sure if screenshot can really help. But check below image where there was no code smell.


Now we triggered a sonar cloud build after a new check in and it changed the code smells as below.

Now when I look into the code smells, the files were checked in long back and not changed in between the above 2 analysis

How about clicking into the 3 new bugs and sharing a screenshot of what issues were raised?

here it is

Hey there.

I wonder if you were affected by this change:

Is your Unit Test Project (where xyzunittest.cs is located) being categorized as a Test Project? You can read more about what that means (and how to tell) here.

Hi Collin,

It should be categorized as test project because the project name has ‘UnitTests’ in it. But can it cause reappearing of old code smells? Can it be solved by adding below line in the project itself? So we need to add it for all the unit test projects, right?
SonarQubeTestProject => true

Thanks!

any updates for the issue?

Not getting any updates for more than 2 weeks. Anyone working on it?

Hey there.

The previously linked post indicates that this is no longer the criteria used to determine if a project is a test project.

Therefore, it’s worth checking how the project being categorized (looking at the analysis logs)

Please note this is a Community forum with volunteers offering help in using SonarSource produccts – this is not an issue tracking system.

Hi Collin,

I was not aware that this is just a forum. We are a paid customer of SonarCloud and they asked us to post the query here. I was expecting some follow ups. Thanks for helping me out btw! I will try to get the logs.

Regards,
Chandrima