Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Hardik-BaseCone opened this issue Jan 9, 2024 · 3 comments
Closed
Labels
question This issue is a question

Comments

@Hardik-BaseCone
Copy link

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 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

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

Thanks,
Hardik

@github-actions github-actions bot added the untriaged To be investigated label Jan 9, 2024
@Bertk Bertk added question This issue is a question and removed untriaged To be investigated labels Jan 13, 2024
@Bertk
Copy link
Collaborator

Bertk commented Jan 13, 2024

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

@Bertk Bertk added the waiting for customer Waiting for customer action label Feb 1, 2024
Copy link

github-actions bot commented May 5, 2024

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

@github-actions github-actions bot added the stale label May 5, 2024
@Bertk Bertk removed waiting for customer Waiting for customer action stale labels Sep 14, 2024
@Bertk
Copy link
Collaborator

Bertk commented Sep 14, 2024

similar #1128

Make sure to Change DebugType from full to portable.

This issue was already fixed using recommended coverlet.collector vstest integration.

Note

Use SonarAnalyzer.CSharp nuget package instead of sonarscanner tool.
The sonarqube warnings are also available in visual studio and can be configured as well using .editorconfig.

@Bertk Bertk closed this as completed Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question This issue is a question
Projects
None yet
Development

No branches or pull requests

2 participants