-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Code Coverage exclusion on line level #23
Comments
@dozer75- can you omit the default statement and put the throw after the switch or does @jakubch1 - In TS/JS there is an |
For several reasons we are not using source code for code coverage so we don't have access to any comments. We are working on IL level where we also try to not detect any patterns as they can change if roslyn will make some changes in future. Few options to fix issue with switch default.
|
@jakubch1 - I was giving an example from another language. It need not be comments. Curious though how is possible to display source code highlighted in green (covered) or red (not covered) without access to the source code. |
To collect code coverage we need dll/exe files and pdb. We are just storing information for example that in file a.cs lines 10-15 are covered and we don't need to read a.cs file. To show highlighting sure we need sources. |
Well, as said, this was an example of code that this request would cover this since this both is the most common "problem" for this and the easiest to reproduce. And yes, there are ways around the problem as well. But most of them are more or less ugly workarounds (like using internal which break good code quality since the methods then are available outside the class). And, as I said, I have no idea how to solve it since I know that CC is not working at code level as said in this thread previously, this was more to throw the issue out and hoping that it could be taken into consideration at some point. (PS: 100% CC is not (and should never be) a requirement, but unnecessary leakages would be nice to have an easy way around no matter what situation like other languages has :) ) |
Description
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 thedefault
statement is never hit (and it impossible to come to that location otherwise).For example, you have a method that looks like this:
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"..
The text was updated successfully, but these errors were encountered: