0

I am using Visual Studio 2019 Professional. For about a year and a half, I've been regularly producing code coverage reports by running a batch file that calls OpenCover to run the analysis and then runs ReportGenerator to process the data into a nice report. This has been working just fine.

But it always bothered me that I have several object classes that probably shouldn't be included in the report, as they just consist of a bunch of properties with getters and setters. So, I was reading yesterday on how to remove such classes from OpenCover's results.

I applied the [ExcludeFromCodeCoverage] attribute to two classes, just to start off with. Then, I adjusted my batch file's single line that calls OpenCover to be as follows:

"%~dp0packages\OpenCover.4.7.922\tools\OpenCover.Console.exe" -register:user -target:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\MSTest.exe" -targetargs:"/testcontainer:\"%~dp0UnitTestProject1\bin\Debug\AppTESTS.dll\"" -skipautoprops -excludebyattribute:"System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage*" -hideskipped:All -output:"%~dp0GeneratedReports\Raw_Report.xml"

Note that the only actual CHANGES I've made to that line were:

  • -skipautoprops
  • -excludebyattribute:"System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage*"
  • -hideskipped:All

Now, the key problem seems to be with the -excludebyattribute.
I've tried different variations:

  • "*.ExcludeFromCodeCoverage*"
  • "*.ExcludeFromCodeCoverageAttribute"
  • "System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute"
  • (and probably a few others I am forgetting)

And I'm still seeing the two classes I'm trying to exclude in the output.

Desperately trying to figure out what I'm doing wrong here.

Could the fact that I'm on Visual Studio 2019 Professional, which doesn't actually include the Visual Studio built-in code coverage functionality/window, have something to do with it? I mean, Visual Studio's only "complaint" about the two [ExcludeFromCodeCoverage] attributes I added was that I needed to add a "using System.Diagnostics.CodeAnalysis;" to each of the two files.

Thanks!

DaveyBoy
  • 435
  • 4
  • 20

1 Answers1

1

So, I decided to test this using a recommendation from the OpenCover's "Usage" documentation (https://github.com/opencover/opencover/blob/master/main/OpenCover.Documentation/Usage.pdf) : creating a brand NEW attribute and using that instead.

I created an "ExcludeFromOpenCoverReportAttribute" class. Modified the references on those two test classes to be [ExcludeFromOpenCoverReport]. Modified that "excludebyattribute" parameter to be:

   -excludebyattribute:"*.ExcludeFromOpenCoverReport*"

Ran the batch file. And now OpenCover (well, ReportGenerator, really) no longer shows those two classes.

I can only conclude that the use of .NET Framework's "ExcludeFromCodeCoverage" attribute does not work in Visual Studio 2019 Pro because the full "Code Coverage Functionality" in Visual Studio is not enabled in "Pro" (but is enabled in the "Enterprise" edition).

Thanks!

DaveyBoy
  • 435
  • 4
  • 20