[CodeCoverage] using coverlet and vstest.console.exe, .xml seems empty but not .coverage file

Hello,

I’m trying to generate coverage to upload to sonar cloud.
tools I’m using.

  • .Net Framwork 4.8
  • SonarScanner.Msbuild.exe
  • VStest.console.exe
  • Coverlet

using github actions when workflow completes I can see .coverage file having data. (almost what I can read in the .coverage file is references to project files)

xml generated after running test: which seems empty and not generating any code coverage data.

<?xml version="1.0" encoding="utf-8"?>
<CoverageSession>
  <Summary numSequencePoints="0" visitedSequencePoints="0" numBranchPoints="0" visitedBranchPoints="0" sequenceCoverage="0" branchCoverage="0" maxCyclomaticComplexity="1" minCyclomaticComplexity="1" visitedClasses="0" numClasses="0" visitedMethods="0" numMethods="0" />
  <Modules />
</CoverageSession>

image

Steps I’m following.

  • setup required tools. e.g. actions/checkout, actions/setup-java, NuGet/setup-nuget, microsoft/setup-msbuild, darenm/Setup-VSTest and downloading sonar-scanner from link https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/6.0.0.81631/sonar-scanner-6.0.0.81631-net-framework.zip

  • SonarScanner.MSBuild.exe begin /k:APPLICATION_NAME /d:sonar.token=MY_VALID_TOKEN

  • msbuild Application.sln -t:rebuild -property:Configuration=Release

  • coverlet C:\a\Repos\App\ –target “vstest.console.exe” --targetargs “**\bin*.Test.Unit*dll /EnableCodeCoverage” --format “opencover” --output \coverage-reports\

  • SonarScanner.MSBuild.exe end /d:sonar.token=MY_VALID_TOKEN

In my application I’m unable to generate code-coverage.
.
.
.
and on other side,
I tried with a sample application with default template .Net Framework 4.8.
added few tests for default code.

which is working fine. In this sample application I can see coverage and xml as well. please have a look on below snapshot from sample app and github workflow.
In this sample application; I follow same steps, except SonarScanner.MSBuild.exe being and end.

image

Please help me here. I don’t know what I’m missing & what doing wrong here.
I’ve tried almost every possible solution from the community. also from the internet and end up with no result.

Thanks,
Hardik

Hey there.

SonarCloud is only involved in reading the coverage reports, it’s not so involved in generating them. That said, we have some documentation that tries to offer help using different tools.

Troubleshooting coverlet is a bit out of scope for this community, but you might try raising an issue on their repository. GitHub - coverlet-coverage/coverlet: Cross platform code coverage for .NET

Let’s say you created a SonarCloud project for this sample application – do you see the coverage uploaded in SonarCloud?

Hello Colin,

Thanks for the update.
I’ve already posted on coverlet issues.
answer - with the sample application, I haven’t tried uploading coverage to sonar cloud. but I’m quite sure it will work; as it has the coverage data in xml file.