Unable to view Code Coverage In Sonar

Greetings
i am unable to view Code Coverage in Sonar Cloud. It does display other stuff but coverage measures are not being displayed.
I am using Azure DevOps pipeline and i have added task Visual Studio test which displays code coverage results on azure but not on sonarcloud.

Hi @ah6557,

Would you please be able to share the Run Code Analysis task logs, if possible in debug mode ? That would help to troubleshoot.

Thank you !
Mickaël

Hi mickaelCaro
Attached are the logs of Code Analysis task.

Kindly go through and let me know if you still need anything from my side.

Regards
RunCodeAnalysis logs.txt (685.6 KB)

Hi @ah6557,

Could you make sure that the /p:PathMap flag on the build step is really needed ? It appears to be set, and for now we are not supporting it (It sets invalid paths to files in the coverage file, so our analyzer cannot find them, based on the absolute path).

Thanks.
Mickaël

Hi
After Removing the paths Code Coverage Results are visible now on sonar cloud. But results that are being displayed in Azure is 62.23% where as in Sonar Cloud in 28.5 % why is there a difference in results can you please suggest.

I saw somewhere in the logs that coverage seems to be computed on the Unit test files themselves. Note that this is not supported on SonarCloud, as tests projects / files, classified as such, are not analyzed at all.

Can you confirm ?

Thanks.
Mickaël

Hi Mickael
you are right code coverage is computed on unit test files it self. So can you please suggest how to overcome with this.

What do you want to achieve precisely ?

Mickael
I want actual code coverage results to be displayed as they are displayed in azure. How can i achieve this?

As i said, by design, all tests files / projects classified as such by our analyzed are not analyzed? There is one exception however, is to add a tag in the .csproj : false

The downside of that if that you’ll get analyzed tests projects / files, but coverage and detections of Unit Tests might not work.

So this is most likely a choose between the 2 worlds.

Mickaël

Mickael
Can you please suggest me what is the best way to achieve actual code coverage results. Should i create an xml or TRx file which may help me?

Hi @ah6557,

The supported scenario is the following

  • You have one or more projects with source code files
  • You have one or more “test” projects, containing unit tests or Integrations tests
  • You run the vs test task (or other tool) that procudes test results files (.trx in case of vstest) and coverage results (.coverage that will be transformed by our Scanner into .coveragexml files)
  • The Scanner for MSBuild is able to detect all of that

Then now, as i said, if you want to get coverage for your unit tests files (do you have unit tests for your unit test files ?), you should specify the following tag in the concerned .csproj :

<SonarQubeTestProject>false</SonarQubeTestProject>

But by doing that, this will lead to bad behavior concerning the coverage of your base source code and subsequent coverage.

The thing is that unit tests projects are not displayed on SonarCloud, to avoid lack of visibility of the “real” source code.

HTH,
Mickaël