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.

[ExcludeFromCodeCoverage] attribute does not work on methods

See original GitHub issue

Hi,

I’ve been struggling with adding [ExcludeFromCodeCoverage] attribute . For some reason, coverlet ignores it when I decorate any method for exclusion. However, it seems to be working fine when I add it to a class. I’ve created a project on github that reproduces this issue.

https://github.com/ssztangierski/coverlet-exclude-attribute

command when I run test from “WeatherControllerTests” folder:

dotnet test WeatherController.Tests.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura

I’d like to exclude CreateHostBuilder method from Program.cs Is this intended or am I doing something wrong? There is also coverage.cobertura.xml file in the repo.

  <class name="CoverageTest.Program/&lt;&gt;c" filename="Program.cs" line-rate="0" branch-rate="1" complexity="1">
          <methods>
            <method name="&lt;CreateHostBuilder&gt;b__1_0" signature="(Microsoft.AspNetCore.Hosting.IWebHostBuilder)" line-rate="0" branch-rate="1">
              <lines>
                <line number="25" hits="0" branch="False" />
                <line number="26" hits="0" branch="False" />
                <line number="27" hits="0" branch="False" />
              </lines>
            </method>
          </methods>
          <lines>
            <line number="25" hits="0" branch="False" />
            <line number="26" hits="0" branch="False" />
            <line number="27" hits="0" branch="False" />
          </lines>
        </class>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

0reactions
ssztangierskicommented, Feb 28, 2020

Thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# ExcludeFromCodeCoverage on method scope not ...
I had found that issue but since we do not use coverlet and the excludefromcodecoverage attribute docs say that it works on method...
Read more >
ExcludeFromCodeCoverage not working for CloseAsync ...
I'm using Sonar-cube to test the code coverage. When I run the report to see the code coverage, it shows that OpenAsync method...
Read more >
ExcludeFromCodeCoverage not working on async methods
A method marked as async returning any Task/Task<> is ignored by the ExcludeFromCodeCoverage attribute. I'm working with Xamarin and some ...
Read more >
ExcludeFromCodeCoverage not working - Build/Test Issues
ExcludeFromCodeCoverage doesn't work here because at a physical level, the attribute doesn't get applied to the compiler-generated IL structure ...
Read more >
ExcludeFromCodeCoverageAttri...
Placing this attribute on a class or a structure excludes all the members of that class or structure from the collection of code...
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