1

I have a .net core solution with two xunit test projects. The build runs on Azure DevOps pipeline and I want to publish the test coverage to a SonarQube (Community) server.

I have basically followed this blog post and it is almost working, the issue is that I only see the coverage of the last test project, not both of them.

I may be wrong but from this issue I guessed that I need to merge my *.coveragexml files before sending to SonarQube.

I have seen that you can merge coverage files with tools like Coverlet but when I tried (from this help page) I got some errors (like Could not find file xunit.runner.reporters.netcoreapp10_101ce3bf-0896-4b2a-9f9e-67d8c0b742e6.pdb)

Before running into this rabbit hole I would prefer to know if I really need to merge my .coveragexml files... and if so can I do it with the regular tools or do I need others like Coverlet...

Cheers

Nicolas C
  • 752
  • 5
  • 18

2 Answers2

0

Here is a very good article about configuring your code coverage and publish it to Sonarqube server.

https://allthingssharepoint.wordpress.com/2018/09/10/getting-coverage-reports-with-net-core/

I am assuming that because of the param passed in dot net test task , your last test project data is overwriting the first test project. You need to ensure that all your test cases would run at one go in the same task.

Task would be like below-

enter image description here

Also while preparing analysis on SonarCloud This is either the SonarCloud task or the SonarQube task. You get them from the Marketplace. Apart from the usual Sonar properties (project, key, version) we need to provide 1 extra property under “Advanced”:

sonar.cs.vscoveragexml.reportsPaths=$(Agent.BuildDirectory)\TestResults\TestCoverage.xml

Please refer this and see if it helps.

Ε Г И І И О
  • 11,199
  • 1
  • 48
  • 63
Mohit Verma
  • 5,140
  • 2
  • 12
  • 27
  • Thanks for the answer but this does not help me, I have already added the SonarQube tasks and configured them. I have also set the parameter sonar.cs.vscoveragexml.reportsPaths to $(Agent.TempDirectory)/**/*.coveragexml (I can't set it to a single TestCoverage.xml as I have 2 reports). I have also (as in the provided link) a task to transform the .coverage to .coveragexml files, and the log show clearly 2 different files, so I don't think they are overwrited (on the azure side at least)... – Nicolas C Mar 19 '19 at 10:03
0

I finally found the issue. You don't need to merge the .coveragexml files, the last version of the SonarScanner.MSBuild.exe actually finds all the .coveragexml files. I looked more closely in the logs and found multiple lines like these:

INFO: Sensor C# Tests Coverage Report Import [csharp]
INFO: Parsing the Visual Studio coverage XML report [...]
INFO: Adding this code coverage report to the cache [...]
INFO: Parsing the Visual Studio coverage XML report [...]
INFO: Adding this code coverage report to the cache [...]

So the .coveragexml files were found and published to sonar.

The reported coverage was false because I needed to add a

<DebugType>Full</DebugType>

In a project. The odd thing is that the other projects reported some code coverage without this property set in the .csproj so I thought I didn't need it.

So if the reported coverage seems false, try adding this property in the csproj.

Nicolas C
  • 752
  • 5
  • 18