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 showing 0% code coverage #1378

Closed
ketanmehra30 opened this issue Sep 12, 2022 · 8 comments
Closed

Coverlet showing 0% code coverage #1378

ketanmehra30 opened this issue Sep 12, 2022 · 8 comments
Labels
Known Issue It's a know issue

Comments

@ketanmehra30
Copy link

ketanmehra30 commented Sep 12, 2022

I have build a Roslyn analyzer with custom rules in .net standard2.0 framework and I have written test cases for rules in .net 4.8 framework project using Xunt. I have setup my coverlet code coverage and install all the required packages in test project but when ever I run the coverlet command : dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura. it gives me 0% in all the coverages

+--------+------+--------+--------+
| Module | Line | Branch | Method |
+--------+------+--------+--------+

+---------+------+--------+--------+
| | Line | Branch | Method |
+---------+------+--------+--------+
| Total | 0% | 0% | 0% |
+---------+------+--------+--------+
| Average | 0% | 0% | 0% |
+---------+------+--------+--------+

@MarcoRossignoli
Copy link
Collaborator

@MarcoRossignoli MarcoRossignoli added the Known Issue It's a know issue label Sep 28, 2022
@GDonets
Copy link

GDonets commented Oct 6, 2022

I tried to follow instructions for datacollector integration, but generated coverage.cobertura.xml still shows 0 coverage

@earloc
Copy link

earloc commented Nov 18, 2022

I have a similar issue and tracked it down so far, that coverlet seems to be unable to instrument files generated by the source-generator.
Details can be found here

(copied from my comment)

Target "InstrumentModules" in file "...\.nuget\packages\coverlet.msbuild\3.2.0\build\coverlet.msbuild.targets" from project "...\repros\30_Empty_CodeCoverage\XUnit.Tests\XUnit.Tests.csproj" (target "InstrumentModulesAfterBuild" depends on it):
       Using "Coverlet.MSbuild.Tasks.InstrumentationTask" task from assembly "...\.nuget\packages\coverletTask "Coverlet.MSbuild.Tasks.InstrumentationTask"
         [coverlet] Unable to instrument module: ...\repros\30_Empty_CodeCoverage\XUnit.Tests\bin\Debug\net6.0\ConsoleApp.dll, pdb without local source files, [...\repros\30_Empty_CodeCoverage\ConsoleApp\TypealizR.SourceGenerators\TypealizR.SourceGenerators.StringLocalizer.SourceGenerator\IStringLocalizerExtensions_ConsoleApp.Resource1.cs]
         [coverlet] Unable to instrument module: ...\repros\30_Empty_CodeCoverage\XUnit.Tests\bin\Debug\net6.0\xunit.assert.dll, embedded pdb without local source files, [C:\Dev\xunit\xunit\src\xunit.assert\Asserts\Assert.cs]
         [coverlet] Unable to instrument module: ...\repros\30_Empty_CodeCoverage\XUnit.Tests\bin\Debug\net6.0\xunit.core.dll, embedded pdb without local source files, [C:\Dev\xunit\xunit\src\common\ExceptionExtensions.cs]
         [coverlet] Unable to instrument module: ...\repros\30_Empty_CodeCoverage\XUnit.Tests\bin\Debug\net6.0\xunit.execution.dotnet.dll, embedded pdb without local source files, [C:\Dev\xunit\xunit\src\xunit.execution\Extensions\ReflectionAbstractionExtensions.cs]
         [coverlet] Unable to instrument module: ...\repros\30_Empty_CodeCoverage\XUnit.Tests\bin\Debug\net6.0\xunit.runner.reporters.netcoreapp10.dll, embedded pdb without local source files, [C:\Dev\xunit\xunit\src\xunit.runner.reporters\Utility\EnvironmentHelper.cs]
         [coverlet] Unable to instrument module: ...\repros\30_Empty_CodeCoverage\XUnit.Tests\bin\Debug\net6.0\xunit.runner.utility.netcoreapp10.dll, embedded pdb without local source files, [C:\Dev\xunit\xunit\src\xunit.runner.utility\Extensions\DisposableExtensions.cs]
         [coverlet] Unable to instrument module: ...\repros\30_Empty_CodeCoverage\XUnit.Tests\bin\Debug\net6.0\xunit.runner.visualstudio.dotnetcore.testadapter.dll, embedded pdb without local source files, [/_/src/xunit.runner.visualstudio/obj/Release/netcoreapp2.1/xunit.runner.visualstudio.dotnetcore.testadapter.Version.cs]
       Done executing task "Coverlet.MSbuild.Tasks.InstrumentationTask".

This does not look connected to https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/KnownIssues.md#vstest-stops-process-execution-early for me.

...\repros\30_Empty_CodeCoverage\ConsoleApp\TypealizR.SourceGenerators\TypealizR.SourceGenerators.StringLocalizer.SourceGenerator\IStringLocalizerExtensions_ConsoleApp.Resource1.cs is a file tha gets generated during the build when my source-generator runs.

@earloc
Copy link

earloc commented Nov 18, 2022

switching to coverlet.collectordoes not seem to solve my issue.

@earloc
Copy link

earloc commented Nov 18, 2022

When I fall back to coverlet.msbuild 2.5.1, everthing seems to be ok.

Starting with coverlet.msbuild 2.6.0 I get empty coverages. (this is no exhaustive analysis, just tested some combinations)

@earloc
Copy link

earloc commented Nov 19, 2022

@MarcoRossignoli would you be so kind and have a look at this? Or should I better create another issue?

@earloc
Copy link

earloc commented Nov 19, 2022

nevermind...my issue was related to #1322. Could fix it.

@daveMueller
Copy link
Collaborator

It is not really clear what the issue is here because of a pretty stale conversation.
The source generator issue mentioned was fixed in the current nightly.
I would suggest to try out the current nightly as we changed the heuristic for detecting assemblies which
most likely also solves this problem (consume nightly). I'm closing this issue now but feel free to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Known Issue It's a know issue
Projects
None yet
Development

No branches or pull requests

5 participants