Feature request: Code Coverage exclusion on line level
@jakubch1 がすでに取り組んでいます。
2022年2月11日 から。
評価
この issue はまだ評価されていません。
説明
Description
This one is a tricky one to find the correct place to report, I have tried to look around in different repos that has issues that mentions
ExcludeFromCodeCoverage(e.g. microsoft/vstest#2658 and dotnet/runtime#45374 ), but it seems that the responsibility for this one is a bit vague since the implementation (dotnet/runtime) and usage of this attribute (microsoft/vstest+ 3rd party vendors) is assigned to different projects. But anyway, here is a description and you can choose how this should be taken further.
Today we have the ExcludeFromCodeCoverage attribute which is by Visual Studio Code Coverage (and other 3rd party vendors) used to exclude code on different levels of code like class, methods, properties and so on.
However, there is one situation where an attribute cannot be used, but I think that it should be some way to do this at that level as well. And that is on code line level.
The problem arises if you for example has a switch where the default statement is never hit (and it impossible to come to that location otherwise).
For example, you have a method that looks like this:
private static bool SomeFunc(AnEnum anEnum)
{
switch(anEnum)
{
case AnEnum.Val1:
// something
return true;
case AnEnum.Val2
// something else
return false;
default:
// This line is never hit since it is stopped by other code, it's only here because a default is needed
// due to return statement in function
throw new ArgumentOutOfRangeException(nameof(anEnum), anEnum, $"The value {anEnum} is not supported.");
}
}
Since this is private method and the calling method already prohibits anEnum values (due to other logic), no tests can hit the default clause. So, it would be nice to exclude that from code coverage. It's simply there for the events when someone screws up something and causes havoc (and the return statement requires some kind of return that won't be hit otherwise a compile error is issued).
I am not sure how this could be solved. My first thought was preprocessor declarations like eg #skipcodecoverage enable #skipcodecoverage disable, but I'm not sure if code coverage can get these preprocessing directives. Other could be that we on ExcludeFromCodeCoverage could set attributes that excludes certain things e.g. [ExcludeFromCodeCoverage(IgnoreSwitchDefault = true)] or [ExcludefromCodeCoverage(IgnoreExceptions=typeof(ArgumentOutOfRangeException)]
Without this possibility it's difficult to get a clean code coverage and you always checks "why did not the code coverage returned % which I'm expecting"..
- 主要言語
- C#
- スター
- 125
- フォーク
- 17
- 平均マージ
- 1時間 15分
- マージ済み PR(30日)
- 2
環境構築
このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/codecoverage のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
microsoft/codecoverage#252 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
microsoft/codecoverage#251 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
microsoft/codecoverage#249 · コメント 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
microsoft/codecoverage#220 · コメント 2 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 66/100
microsoft/codecoverage#218 ·
microsoft/codecoverage の issue をすべて見る
似ている issue
-
copilot documentation
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 2 日以内に返信
-
needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
spectreconsole/spectre.console#2221 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
godotengine/godot-docs#12428 ·
メンテナーはふだん 1 日以内に返信
-
.NET triage
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
microsoft/semantic-kernel#14526 ·
メンテナーはふだん 4 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信