Visual Studio 2019: Code Coverage Results says "Not Covered" despite unit tests existing

Viewed 902

I have a .NET Core (net5.0) Visual Studio 2019 API project with an MSTest unit test project. I also have a solution-wide codecoverage.runsettings file. The problem is that, even though I've mocked (using the Moq Nuget Package) and written unit tests for all of my public Controller methods, have decorated my Controller's private methods with [ExcludeFromCodeCoverage], and have added exclusions in my .runsettings file, the Code Coverage Results window still shows 0% coverage:

enter image description here

(Note that I have blacked out the top-level namespace and other potentially sensitive information).

You will notice that my Controller class is listed twice (SpliceController.<>c and just plain old SpliceController.....I have no idea what the <>c means). All the methods under SpliceController.<>cdo in fact have associated unit tests (you will also notice that the method UploadAttachments is listed multiple times for some reason). Under SpliceController the single method GetUserNameFromClaims is a private helper method decorated with [ExcludeFromCodeCoverage] so it should not be in this list. Notice that everything is listed as "not covered".

If it helps, here is the CodeCoverage section of my .runsettings file:

            <CodeCoverage>
              <ModulePaths>
                <Include>
                  <ModulePath>.*\.dll$</ModulePath>
                  <ModulePath>.*\.exe$</ModulePath>
                </Include>
                <Exclude>
                  <ModulePath>.*CPPUnitTestFramework.*</ModulePath>
                  <ModulePath>.*Splice.API.Model.dll</ModulePath>
                  <ModulePath>.*Splice.API.Test.dll</ModulePath>
                  <ModulePath>.*moq\.dll$</ModulePath>
                  <ModulePath>.*newtonsoft\.json\.dll$</ModulePath>
                  <ModulePath>.*netcore\.dll$</ModulePath>
                </Exclude>
              </ModulePaths>
              <Functions>
                <Exclude>  
                  <Function>.*MoveNext.*</Function>
                  <Function>.*DisplayClass.*</Function>
                  <Function>.*Services\.</Function>
                  <Function>.*Response\.</Function>
                  <Function>.*Migrations\.</Function>
                  <Function>.*Helpers\.</Function>
                  <Function>.*Filter\.</Function>
                  <Function>.*Startup\.</Function>
                  <Function>.*Program\.</Function>
                  <Function>.*EF\.</Function>
                </Exclude>
              </Functions>
              <UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
              <AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
              <CollectFromChildProcesses>True</CollectFromChildProcesses>
              <CollectAspDotNet>False</CollectAspDotNet>
            </CodeCoverage>
0 Answers
Related