Reputation: 11570
I have observed that the "ExcludeFromCodeCoverage" attribute is not supported within the Portable Class Library.
Is there any workaround for filtering code coverage for business logic within a dll?
Hence, I usually apply this attribute on property getters/setters and code behind files.
Upvotes: 1
Views: 2125
Reputation: 23924
I found that if you add your own ExcludeFromCodeCoverageAttribute
implementation that the VS coverage tool will obey it. However, you have to put it in the right namespace, too. YMMV.
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>
/// Specifies that the attributed code should be excluded from code coverage information.
/// </summary>
/// <remarks>
/// This attribute was added to the assembly because it's not otherwise
/// available to portable class libraries. Marked internal to avoid reuse
/// outside this specific library.
/// </remarks>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event, AllowMultiple = false, Inherited = false)]
internal sealed class ExcludeFromCodeCoverageAttribute : Attribute
{
}
}
Upvotes: 4
Reputation: 11570
Referencing a similar question, I have swapped out the [ExcludeFromCodeCoverage] attribute with [DebuggerNonUserCode].
This works for me.
Upvotes: 1
Reputation: 3432
Usually Code Coverage libraries allow you to specify what attribute to exclude. So you could just create your own attribute and configure the coverage util to use that as its exclusion criteria.
Upvotes: 0