microsoft / microsoft/codecoverage

ExcludeFromCodeCoverage for interface with default implementations

Open
#143 0 comments 1 reaction 1 assignee View on GitHub

@fhnaseer is already working on this.

Since Nov 18, 2024.

enhancement
Dominant language
C#
Stars
125
Forks
17
Avg merge
1h 17m
Merged PRs (30d)
2

Description

Currently the ExcludeFromCodeCoverage attribute can only be placed on classes, constructors, methods, structs, properties, events and assemblies. However, now that C# 8.0 introduced interfaces with default implementations it could be useful to be able to be able to use the attribute on these as well.

As an example, in the visitor pattern I'm using an interface with default implementation so that visitors don't have to override every method:

public interface IVisitor
{
    void Visit(FullName fullName) => throw new NotImplementedException();
    void Visit(Address address) => throw new NotImplementedException();
    void Visit(PhoneInfo phoneInfo) => throw new NotImplementedException();
}

Since testing these concrete methods (in my case) is not necessary, I would like to tag the interface with the ExcludeFromCodeCoverage attribute which is currently not possible. While I've got a few workarounds (adding the ExcludeFromCodeCoverage attribute to every single method declaration in the interface or using an abstract class and tagging the class itself) it might be worth letting the attribute be placed directly on interfaces.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.