-
Notifications
You must be signed in to change notification settings - Fork 386
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
0% coverage of library when using source generator #1262
Comments
I have the same problem using XUnit and .NET 5.0 projects. Run the code coverage, and the resulting coverage.cobertura.xml file will be empty. To show it is working without the generators, remove the following line from Playground.csproj. IDE might need a restart for it to work. Then the code coverage report is filled. <ProjectReference Include="..\Playground.CodeGeneration\Playground.CodeGeneration.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> The code that is generated has no influence when it is added without the generator. I also tried various ways to call the generators ( |
This may indicate the issue, but very obliquely. Coverlet uses a heuristic to determine which libraries are relevant to instrument, to avoid instrumenting third-party libraries. This is to look for the source code files, and if not all of them are found consider the DLL external. Source generators produce source files that coverlet can't see, so that will lead to this issue. However, it knows about the conventional suffix I've logged an issue on making this heuristic configurably less harsh, but it is yet open since I haven't had time to work on it (nor anyone else): #1164 |
@Andreas-Huber , thanks for reply.
I'm just wondering if the issue is related to suffix .g.cs in generated files. In my project I used only .cs. |
Ah sorry, I was already ahead and pushed a new commit after Peters comment with the .g.cs suffix - it was not there before. So in this case adding .g.cs definitely fixed it. |
@petli Thanks again for the explanation. The |
Thanks for help! Changing filename to .g.cs fixed the issue for me too. |
Hello,
I have a library targeted .Net Standard 2.0 and a test project using NUnit and targeted .Net 5.0.
I used coverlet to calculate code-coverage as described in https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-code-coverage?tabs=windows.
Recently I started to use ISourceGenerator to generate some files during build.
After that I noticed that code coverage emits coverage.cobertura.xml file with the following content :
I played much with coverlet.collector v3.1.0 and coverlet.msbuild v3.1.0 but always got an empty report (0 lines being covered).
Here is an output of command :
File log.datacollector.21-11-29_18-08-30_12299_4.txt keeps a message :
In log.host.21-11-29_18-08-30_74105_4.txt I noticed a bunch of messages like :
Could somebody please assist to understand what is wrong ?
Also, coverlet works fine when I remove compile-time code-generation.
PS :
runsettings.xml :
The text was updated successfully, but these errors were encountered: