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

Coverage collection disappears when project has a reference to StrawberryShake.CodeGeneration.CSharp.Analyzers #1170

Closed
nover opened this issue Jun 2, 2021 · 3 comments

Comments

@nover
Copy link

nover commented Jun 2, 2021

I have a project where code-coverage with coverlet worked perfectly, but have now added an typed graphql client to this project, using the StrawberryShake client, which adds the package StrawberryShake.CodeGeneration.CSharp.Analyzers that injects a roslyn analyser which auto-generates code.

I have tried many variations of flags to coverlet, like:

dotnet test --no-build --no-restore  src/TestUnit/ /p:CopyLocalLockFileAssemblies=true /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=cobertura     

When I exclude the above package, I get output resembling this:

Test run for /src/TestUnit/bin/Debug/net5.0/TestUnit.dll (.NETCoreApp,Version=v5.0)
Microsoft (R) Test Execution Command Line Tool Version 16.8.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.

Passed!  - Failed:     0, Passed:   254, Skipped:     0, Total:   254, Duration: 818 ms - /src/TestUnit/bin/Debug/net5.0/TestUnit.dll (net5.0)

Calculating coverage result...
  Generating report 'TestResults/coverage.cobertura.xml'

+------------------------+--------+--------+--------+
| Module                 | Line   | Branch | Method |
+------------------------+--------+--------+--------+
| ServiceA.ServiceClient | 27.56% | 21.6%  | 22.77% |
+------------------------+--------+--------+--------+
| ServiceA.Abstractions  | 0%     | 100%   | 0%     |
+------------------------+--------+--------+--------+
| ServiceA.Service       | 0.83%  | 0%     | 2.34%  |
+------------------------+--------+--------+--------+

When I include the package again in my .csproj file the entire ServiceA.ServiceClient line disappears from the coverlet output.

Other technical details for debugging this:

  • macOS Catalina
  • dotnet 5.0.101
  • coverlet.msbuild 3.0.3
  • coverlet.collector 3.0.3
  • Microsoft.NET.Test.Sdk 16.9.1
@petli
Copy link
Collaborator

petli commented Jun 4, 2021

This is likely the same issue that generated source files should have the somewhat conventional .g.cs suffix for Coverlet to recognise them, which StrawberryShake probably doesn't follow resulting in this issue. See also #1164 for a more general solution to this.

@nover
Copy link
Author

nover commented Jun 6, 2021

@petli

Interesting - I'll try to see if I can get it to work and perhaps raise an issue with the StrawberryShake team.

@nover
Copy link
Author

nover commented Jun 10, 2021

According to the authors of StrawberryShake, this is a probably a problem with roslyn and not coverlet - they also provided a workaround.

@nover nover closed this as completed Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants