Why I use [ExcludeFromCodeCoverage]
Somtimes it is not possible or too expensive to create a Unit Test for special code. So C# has the attribute [ExcludeFromCodeCoverage] to exclude this code from Coverage Analyse.
Samples for [ExcludeFromCodeCoverage]
- Azure functions Clue Code. This code get called by environment and call directly testet code.
- Mocked Code. I mock some function away so because it schould not called by unit tests for some resons. (Send error reports, change DB) etc.
- Unused Interface implementations. Sometimes a API gives you an interface and you have to implement all methodes but some are not used.
- Simple get/set Properties.
ExcludeFromCodeCoverage Closed Ticked
I come from the closed Ticket: Do not skip source files that contains "ExcludeFromCodeCoverage*" attributes · Issue #428 · SonarSource/sonar-dotnet · GitHub
Feature Request: What I want
It would be fine if Code marked with [ExcludeFromCodeCoverage] is not included in Code Coverage analyse. But is still used for Clean Code analyse.
What I use
- Enterprise Edition Version 9.6 (build 59041)