I know i was able to use [ExcludeFromCodeCoverage]
to exclude code coverage in .Net framework 4.
Does anyone know if there's a way i can exclude code coverage from .dotnet core?
Since .NET Core 2.0 you can use ExcludeFromCodeCoverage
attribute.
using System.Diagnostics.CodeAnalysis;
namespace YourNamespace
{
[ExcludeFromCodeCoverage]
public class YourClass
{
...
}
}
https://isscroberto.com/2019/07/11/net-core-exclude-from-coverage/
I finally found solution!
First of all you need to use .runsettings file to configure code coverage:
https://msdn.microsoft.com/en-us/library/jj159530.aspx
BUT the problem is that ExcludeFromCodeCoverageAttribute is sealed so we can't use it
https://github.com/dotnet/corefx/blob/93b277c12c129347b5d05de973fe00323ac37fbc/src/System.Diagnostics.Tools/src/System/Diagnostics/CodeAnalysis/ExcludeFromCodeCoverageAttribute.cs
I posted question here and looks like it will be solved in next release
https://github.com/dotnet/corefx/issues/14488
FOR NOW I use GeneratedCodeAttribute as mentioned in .runsettings example. You can also use your custom attribute or any other exclude rule like here:
https://msdn.microsoft.com/en-us/library/jj159530.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With