.NET Core Exclude from Coverage

It’s great to have your code covered by tests, right? And if you’re like me, you’d like to know how much of your code gets covered, the higher this metric, the lower the chance of having undetected software bugs, assuming your tests are good quality, of course.

Sometimes you need to exclude some classes from this metric to get more accurate results according to your project specifics.

For a .NET Core project, the framework provides the attribute ExcludeFromCodeCoverage. Tag your class with it and make sure to add the import to System.Diagnostics.CodeAnalysis.

This attribute is available to .NET Core 2.0 or superior.

using System.Diagnostics.CodeAnalysis;
namespace YourNamespace
public class YourClass

view raw
hosted with ❤ by GitHub

tired good night GIF