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

[BUG] Constructorless ControllerBase implementations produce no code coverage #1727

Open
chrish619 opened this issue Jan 3, 2025 · 0 comments
Labels
untriaged To be investigated

Comments

@chrish619
Copy link

chrish619 commented Jan 3, 2025

Describe the bug
When producing code coverage for a WebApi/MVC project, if a Controller has no explicit constructor, it may not produce any code coverage results for the entire file.

These Controllers/Classes seem to be affected by the ExcludeByAttribute=CompilerGeneratedAttribute switch - as removing this option produces code coverage for these files.

To Reproduce
Sample Repository: https://github.com/chrish619/coverlet-coverage-issue-20250103/

Controller must inherit from either ControllerBase, or another constructor-less Controller abstraction.
ExcludeByAttribute in either MSBuild property flags, or a runsettings file, must contain CompilerGeneratedAttribute.

Expected behavior
WebApi/MVC Controllers without an explicit constructor, should produce code coverage results.

Actual behavior
WebApi/MVC Controllers without an explicit constructor produces no code coverage results when
ExcludeByAttribute=CompilerGeneratedAttribute is used.
These Controllers may use Actions with [FromServices] dependency injection - whilst also not declaring a constructor.

WebApi/MVC Controllers with an explicit constructor will always produce code coverage results.

Configuration (please complete the following information):
Please provide more information on your .NET configuration:

  • Which coverlet package and version was used? 6.0.2/6.0.3
  • Which version of .NET is the code running on? .Net8/.Net9
  • What OS and version, and what distro if applicable? Windows 10
  • What is the architecture (x64, x86, ARM, ARM64)? x64
  • Do you know whether it is specific to that configuration? Specifically caused by ExcludeByAttribute=CompilerGeneratedAttribute
@github-actions github-actions bot added the untriaged To be investigated label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged To be investigated
Projects
None yet
Development

No branches or pull requests

1 participant