Domanda

There are some blocks in our codebase that are either boilerplate or not reachable except in extraordinary cases (e.g. photons hitting the code at the right place and time).

These blocks are at a statement level, not at the class or method level. For class and method, Visual Studio will ignore [ExcludeFromCodeCoverage], but of course you can't attribute statements or statement blocks.

Is there some way to do this I've missed in the documentation? I've searched and there doesn't seem to be anything. If there is not a way, does it make sense to refactor the code? I don't want to spend too much time on this, but enough to keep the coverage amount high or 100% on the "important" things.

È stato utile?

Soluzione

No, there is no way to prevent VS Code Analysis from inspecting a subset of statements in a method. If you do not want to fix the violations generated by these statements, your best bet might be to add suppressions with a standardized justification that allows you to easily identify them later if necessary. e.g.:

[SuppressMessage("Some.Category", "CA9999:SomeRule",
    Justification = "Boilerplate code ignored under departmental policy.")]

That said, my own preference would generally be to clean these up rather than hide them, but ymmv...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top