Reputation: 2014
using MyAPI.ShippingAddress.Operations;
using MyAPI.ShippingAddress.Request;
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics.CodeAnalysis;
namespace MyAPI
{
public class DependencyServiceFactory
{
[ExcludeFromCodeCoverage]
public void Add(int a, int b)
{
return a + b;
}
}
}
I created asp.net core 3.1 MS unit test project and everything work as expected but [ExcludeFromCodeCoverage] not working. I need to remove this method from code coverage result
Any suggestion ?
Upvotes: 1
Views: 1119
Reputation: 2014
Add CodeCoverage.runsettings file and configure it using test explore. CodeCoverage.runsettings file should be contain "System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute"
<Attributes>
<Exclude>
<Attribute>^System\.Diagnostics\.DebuggerHiddenAttribute$</Attribute>
<Attribute>^System\.Diagnostics\.DebuggerNonUserCodeAttribute$</Attribute>
<Attribute>^System\.Runtime\.CompilerServices.CompilerGeneratedAttribute$</Attribute>
<Attribute>^System\.CodeDom\.Compiler.GeneratedCodeAttribute$</Attribute>
<Attribute>^System\.Diagnostics\.CodeAnalysis.ExcludeFromCodeCoverageAttribute$</Attribute>
</Exclude>
</Attributes>
Upvotes: 1