coverlet-coverage / coverlet

Cross platform code coverage for .NET
MIT License
2.99k stars 385 forks source link

Assembly marked as ExcludeFromCodeCoverage is not excluded #290

Closed SefaOray closed 5 years ago

SefaOray commented 5 years ago

Description When an assembly decorated with ExcludeFromCodeCoverage attribute, it is not excluded from coverage report.

Repro steps Example code:

using System.Diagnostics.CodeAnalysis;
using System

[assembly: ExcludeFromCodeCoverage]
namespace ExampleNs
{
    public class ExampleClass:
    {
        public Guid Id { get; set; }
    }
}

Expected behavior Assembly is excluded from the coverage report

Actual behavior Assembly is included in the coverage report

Known workarounds Passing the assembly with --exclude "[Assembly]*" works

Related information Cross platform .NET Core code coverage tool version 1.3.0.0 Visual Studio Version: Visual Studio Professional 2017 Microsoft (R) Test Execution Command Line Tool Version 15.9.0 Test project build with .Net Core 2.1

tonerdo commented 5 years ago

@SefaOray exclusion attributes don't work on assemblies by design. The --exclude property is provided for achieving the same.

sshukurov commented 5 years ago

@tonerdo could you please clarify? I have the same issue here, and ExcludeFromCodeCoverage must work on assemblies https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.excludefromcodecoverageattribute.

tonerdo commented 5 years ago

exclusion attributes don't work on assemblies by design

@sshukurov by this I mean that Coverlet doesn't check for attributes on assemblies. It does however, have an exclude option that supports specifying assemblies

sshukurov commented 5 years ago

@tonerdo it's a pity. I want to define all my exclusions in code, so that different code coverage tools can reuse them.

zmhh commented 5 years ago

Agree that ExcludeFromCodeCoverage should work for assemblies unless there is a reason not to.

olivier-spinelli commented 5 years ago

This should be supported. May this issue be reopened? (And eventually handled... this should not be too complicated to implement.)

bhales42 commented 5 years ago

This would be useful. I usually execute unit tests and coverage multiple ways: IDE, command line, etc. Declaring this in an assembly attribute would apply to all methods.

MarcoRossignoli commented 5 years ago

@tonerdo I re-opened this issue, I think we should support this behaviour because it's a default for most coverage tools. If you don't agree please let me know. @petli what do you think?

MarcoRossignoli commented 5 years ago

Guys if someone of you can trust the feature we'll be more confident. Will be testable with nightly build tomorrow you can follow this steps https://github.com/tonerdo/coverlet/blob/master/Documentation/ConsumeNightlyBuild.md

simonness commented 4 years ago

@MarcoRossignoli @tonerdo this is exactly what we need :) Is there an ETA for when this fix will be released?

MarcoRossignoli commented 4 years ago

@simonness can you try with nightly to confirm the fix?

Is there an ETA for when this fix will be released?

We don't have a strict release plan at the moment(we're working on it) my idea is one release every quarter(if there are bug we'll release immediatly), so I think for the end of the year, last release 23 Sep https://github.com/tonerdo/coverlet/blob/master/Documentation/ReleasePlan.md#proposed-next-versions

ghost commented 4 years ago

I still see the same issue in VS 2019 with collector v.1.3.0. Can someone help?

MarcoRossignoli commented 4 years ago

@pedramrezaei can you open a new issue?Do you want to skip all assembly?

flytrapper commented 3 years ago

When you look at the attribute (link below) it specifies it is valid on assemblies, yet it doesn't change the output. Is this an error in documentation?

https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.excludefromcodecoverageattribute?view=net-5.0

sbojarczak commented 1 year ago

guys, does it work already? if yes, from which version?