-
Notifications
You must be signed in to change notification settings - Fork 388
ExcludeFromCodeCoverage not working for autogen getters and setters #269
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
Comments
Similar thing happens with async methods which are read like this (with MoveNext stuff):
and then all attributes are lost when |
try: public int MyProperty { [ExcludeFromCodeCoverage] get; [ExcludeFromCodeCoverage] set; } |
@SlowLogicBoy that workaround does work, but I'd say we need to get something in place that iterates the Properties collection in the Honestly, I don't even think we'd have to support properties, we could just add the |
Thank's for the hack @SlowLogicBoy |
Use workaround from coverlet-coverage/coverlet#269 (comment)
@pape77 is this issue still here? |
Now we can use |
@SlowLogicBoy @MarcoRossignoli - this is still a problem for properties Should this issue really be closed? |
This issue is old can you open new one? |
I was going to but found that a similar issue was opened after this and was closed as a duplicate of this. |
@MarcoRossignoli As far as I can tell this was never actually fixed so closing this was not legitimate action. There is no PR or commit linked to this, just a comment for what looks like an msbuild property. Besides like I said, other issues were opened for this same problem and were closed as duplicates of this. |
@StingyJack which version are you using?can you provide a repro? Can you try also the new feature to skip autoprop?https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/MSBuildIntegration.md#skip-auto-implemented-properties |
Both versions 1.3.0 and 3.0.3 had the same problem. I'm not invoking this by command line, another tool is doing the invocation that I don't have immediate control of. The repro is to put a property in a class, run coverage, see that it's uncovered, then apply the excluded attribute on the property and rerun coverage. It still shows up as uncovered. The workaround of applying the attribute to each the get and set does work, but leaves messy code EDIT: Perhaps an example can explain better. //when using this, it reports the property as "not covered"
public class User
{
[ExcludeFromCodeCoverage]
public object Id { get; set; }
...
}
//when using this, it reports the property as "covered", but seems like it should not be necessary.
public class User
{
public object Id { [ExcludeFromCodeCoverage] get; [ExcludeFromCodeCoverage] set; }
...
} |
Also I dont want to skip auto properties in the first place. Any property that is not listed as covered by a unit test is something that may be unused by the code and can be removed (YAGNI), or something I should have an assertion for in a unit test (and thus make covered). There are just some fields that are handled by an ORM or DB driver that I wouldn't unit test for, or temporary cases where the properties are needed by someone else's code that will be covering them later, but my PR needs to meet or exceed a coverage threshold to be merged. Usages of |
Ok reopening for further investigation |
Noticed that when trying to apply the excludeFromCoverage attribute to getters and setters from a
class property, they are not taken into account
This can easily be seen in action in existing tests within coverlet. In
InstrumenterTests.cs
, in theTestInstrument_ClassesWithExcludeAttributeAreExcluded
Just remove the [ExcludeFromCodeCoverage] attribute from one of the classes that this method uses in
Samples.cs
and add a property like thisId
one.For example in
Samples.cs
change this class as follows:Then you will that in method
InstrumentType
fromInstrumenter.cs
the attributes don't show up, because the method name is changed toget_Id()
(autogenerated) and so it gets instrumented anyway.Can we fix this somehow?
The text was updated successfully, but these errors were encountered: