question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Code coverage stops working if assembly contains interfaces from source generators

See original GitHub issue

_Originally posted as https://github.com/reactiveui/refit/issues/1073_

Describe the bug

In a project using Refit 6.0.8 and coverlet.msbuild 3.0.2, upon updating from Refit 5.2.4, code coverage is no longer being collected for the assembly containing Refit interfaces.

Using coverlet’s troubleshooting guide here, I narrowed my investigation down to this line of interest:

[coverlet] Unable to instrument module: C:\Coding\Projects\MyProject\tests\MyProject.Tests\bin\debug\net5.0\MyProject.dll, pdb without local source files, [C:\Coding\Projects\MyProject\src\MyProject\InterfaceStubGenerator.Core\Refit.Generator.InterfaceStubGenerator\IMyApi.g.cs]

As there’s no file on disk here, that sort of makes sense, but causes an issue as it breaks all code coverage for the project for the sake of the one interface.

I’m guessing this is something to do with the usage of source generators in Refit.

The failure then slipped through several CI jobs for Refit updates until it was noticed due to https://github.com/coverlet-coverage/coverlet/issues/1083.

Steps To Reproduce

Clone https://github.com/martincostello/alexa-london-travel and run ./build.ps1.

The build script will eventually output something like this:

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

+---------+------+--------+--------+
|         | Line | Branch | Method |
+---------+------+--------+--------+
| Total   | 100% | 100%   | 100%   |
+---------+------+--------+--------+
| Average | NaN% | NaN%   | NaN%   |
+---------+------+--------+--------+

Example build: https://github.com/martincostello/alexa-london-travel/runs/1869767942?check_suite_focus=true#step:4:78

This seems to be affecting multiple repos I have using Refit, not just this one.

Here’s another example: https://github.com/martincostello/alexa-london-travel-site/runs/1870035564?check_suite_focus=true#step:4:160

Expected behavior

Assemblies containing Refit interfaces are instrumented correctly.

For the referenced repository, it should output something like this from build.ps1:

+--------------------+-------+--------+--------+
| Module             | Line  | Branch | Method |
+--------------------+-------+--------+--------+
| LondonTravel.Skill | 99.1% | 94.82% | 97.9%  |
+--------------------+-------+--------+--------+

+---------+-------+--------+--------+
|         | Line  | Branch | Method |
+---------+-------+--------+--------+
| Total   | 99.1% | 94.82% | 97.9%  |
+---------+-------+--------+--------+
| Average | 99.1% | 94.82% | 97.9%  |
+---------+-------+--------+--------+

Example build: https://github.com/martincostello/alexa-london-travel/runs/1869465349?check_suite_focus=true#step:4:80

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:30 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
martincostellocommented, Feb 21, 2021

Thanks Marco ❤️

2reactions
MarcoRossignolicommented, Feb 17, 2021

Will this also fix the coverlet.console? @MarcoRossignoli

Yep the engine in shared between “drivers”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code using generated code builds successfully but shows ...
SourceGenerators : Code using generated code builds successfully but shows errors in the IDE as if no code was generatedClosed - Fixed View...
Read more >
Unit Testing Source Generators - Build/Test Issues
With the latest update, code coverage is disabled in unit tests. This makes sense for when the project actually uses source generation during...
Read more >
Troubleshoot code coverage - Visual Studio
The code coverage tool works by inserting instrumentation into an assembly just before the application starts running.
Read more >
How to test or exclude private unreachable code from ...
I have a bunch of assemblies with near 100% test coverage but I often run into a situation like in the example below....
Read more >
Building a Source Generator for C# - InfoQ
The source generator is defined using the ISourceGenerator attribute and the ISourceGenerator interface. Both can be found in the Microsoft. ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found