Feature request: Code Coverage exclusion on line level
@jakubch1 ya está trabajando en esto.
Desde el 11/2/2022.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
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"..
- Lenguaje dominante
- C#
- Estrellas
- 125
- Forks
- 17
- Merge medio
- 1 h 15 min
- PR fusionados (30 d)
- 2
Preparar el entorno
Aún no hemos revisado los archivos de configuración de este proyecto. Empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/codecoverage
-
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
microsoft/codecoverage#252 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 52/100
microsoft/codecoverage#251 ·
-
[BUG] Intermittent Windows 0xC0000005 crashes in MTP test hosts with CodeCoverage on .NET 10Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
microsoft/codecoverage#249 · 1 comentario ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
microsoft/codecoverage#220 · 2 comentarios ·
-
False positive branch coverageAbierto
Dificultad 3/5 1-2 días Aptitud para principiantes 66/100
microsoft/codecoverage#218 ·
Todos los issues de microsoft/codecoverage
Issues similares
-
copilot documentation
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 2 días
-
[Rust][Flaky Test] multiple_deadlines_fire_in_order asserts a wall-clock gap instead of firing orderAbiertoCI/CD ⚒️ Flaky-tests 🐦
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
valkey-io/valkey-glide#7255 ·
Los mantenedores suelen responder en 3 días
-
bug good first issue
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
unoplatform/Uno.Core#99 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
aws/aws-dotnet-ai#75 ·