coverlet-coverage / coverlet

Cross platform code coverage for .NET
MIT License
2.93k stars 385 forks source link

coverlet with vstest.console.exe not generating code coverage. #1580

Open Hardik-BaseCone opened 5 months ago

Hardik-BaseCone commented 5 months ago

Hello,

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

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

xml generated after running test is as below: 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

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 let me know if you want to take a look at my sample applications workflows .yml file.

Thanks, Hardik

Bertk commented 5 months ago

Hi, could you please provide addition information:

Configuration (please complete the following information): Please provide more information on your .NET configuration:

  • Which coverlet package and version was used?
  • Which version of .NET is the code running on?
  • What OS and version, and what distro if applicable?
  • What is the architecture (x64, x86, ARM, ARM64)?
  • Do you know whether it is specific to that configuration?

Typically dotnet test and coverlet.collector are the recommended tools and before running the test a dotnet publish might be helpful. Why do you use msbuild instead of dotnet?

see also https://docs.sonarsource.com/sonarqube/9.8/analyzing-source-code/scanners/sonarscanner-for-dotnet/#net-core-and-net-core-global-tool-invocation

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 3 months with no activity.