5

I have an ASP.NET project and I'm using ReSharper to do my unit testing along with dotCover. I'm looking for a way to mark a method as not needing to be tested. I For example, I have some simple one-liner methods that send work elsewhere and return the result. The methods that do the actual work are covered by unit tests, but these "intermediate" methods don't need to be.

These methods will show as uncovered by ReSharper. I'd like to be able to flag them so they don't show as covered or uncovered. This would let me explicitly state when I have code that, for whatever reason, will be excluded from my unit tests and does not need to be concerned about being covered.

Phil Ringsmuth
  • 2,037
  • 4
  • 20
  • 29
  • 2
    Have you tried regular solutions found by https://www.bing.com/search?q=c%23+exclude+from+code+coverage like https://stackoverflow.com/questions/1602898/how-to-decorate-a-class-as-untestable-for-code-coverage – Alexei Levenkov Mar 23 '18 at 18:15
  • The SO link you put in there is exactly what I needed. Thank you! – Phil Ringsmuth Mar 23 '18 at 18:44
  • Why not simply run same tests, but call method under the tests through your "one-liner" methods? – Fabio Mar 25 '18 at 16:47

1 Answers1

2

Thanks to Alexei Levenkov, a similar question with a great answer has already been asked. In short, ASP.NET now has an [ExcludeFromCodeCoverage] attribute that can be added to a class or a method. Once ReSharper re-analyzed my code coverage, it no longer shows these methods as uncovered.

https://stackoverflow.com/a/1603193/529554

Phil Ringsmuth
  • 2,037
  • 4
  • 20
  • 29
  • 3
    For clarity, the [ExcludeFromCodeCoverage](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.excludefromcodecoverageattribute?redirectedfrom=MSDN&view=netframework-4.7.2) attribute is nothing to do with ASP.NET – Richardissimo Aug 16 '18 at 20:38