8

I have 20 projects in my .SLN file. I am running my unit tests through the Test Explorer and generating the code coverage. Only eight of the projects show up in the coverage (see screenshots). I am using a runsettings file in which I have commented out the contents of all of the <exclude> tags, like so:

        <PublicKeyTokens>
          <!-- Exclude Visual Studio extensions: -->
          <Exclude>
            <!--
            <PublicKeyToken>^B77A5C561934E089$</PublicKeyToken>
            <PublicKeyToken>^B03F5F7F11D50A3A$</PublicKeyToken>
            <PublicKeyToken>^31BF3856AD364E35$</PublicKeyToken>
            <PublicKeyToken>^89845DCD8080CC91$</PublicKeyToken>
            <PublicKeyToken>^71E9BCE111E9429C$</PublicKeyToken>
            <PublicKeyToken>^8F50407C4E9E73B6$</PublicKeyToken>
            <PublicKeyToken>^E361AF139669C375$</PublicKeyToken>
            -->
          </Exclude>
        </PublicKeyTokens>

I cannot figure out why the other 12 projects are not shown in the coverage results. Any ideas?

Solution Projects:

Visual Studio Project Listing

Code Coverage Results:

enter image description here

michaelkoss
  • 516
  • 7
  • 19

4 Answers4

11

The assemblies are not showing up as they are not loaded during the current test run.

Add some simple tests that use a type in each of the other assemblies.

Shaun Wilde
  • 8,228
  • 4
  • 36
  • 56
11

Adding <DebugType>Full</DebugType> to target .csproj file, worked for me

<PropertyGroup>
     <TargetFramework>netstandard2.0</TargetFramework>
     <DebugType>Full</DebugType>
</PropertyGroup>
Victor SDK
  • 353
  • 3
  • 13
  • 1
    Had this issue with VS Enterprise 2017, this fixed it. – Nathan Nov 08 '19 at 13:17
  • Thank you, Thank you, Thank you - this just fixed my VS Pro 2019 issue using DotCover (Resharper) - and one of my projects refusing to appear in my Coverage report!! – yeti_c Jun 01 '21 at 23:20
0

Ancient thread, but I needed to do this to pick up code coverage numbers if someone added a project and didn't add any tests or even references to the new assemblies. The solutions above weren't working so... Hackier than I'd like but this works for me.

Note, if you don't ensure this runs at the VERY END you'll get duplicates in your CodeCoverage output for libraries that are loaded after this code, so I'm not sure how you could do this if you have multiple test projects as there isn't a "TestRunCleanupAttribute" that I know of.

        [AssemblyCleanup]
        public static void LoadAllAssemblies()
        {
            var existingAssemblies = AppDomain.CurrentDomain.GetAssemblies().Where(x => !x.IsDynamic).Select(x => new FileInfo(x.Location).Name).ToList();

            var testAssembly = new FileInfo(Assembly.GetExecutingAssembly().Location);
            DirectoryInfo di = testAssembly.Directory.Parent.Parent.Parent; // specific to your solution structure
            var assemblies = di.GetFiles("*MyCommonDllName*.dll", SearchOption.AllDirectories);
            assemblies.Concat(di.GetFiles("*MyCommonDllName*.exe", SearchOption.AllDirectories));

            foreach (var assem in assemblies)
            {
                if (!existingAssemblies.Contains(assem.Name))
                {
                    Assembly.LoadFile(assem.FullName);
                    existingAssemblies.Add(assem.Name);
                }
            };
        }
-1

Could you not also add:

      <CodeCoverage>
        <ModulePaths>
          <Include>
             <!--Include all loaded .dll assemblies and .exe executables-->
            <ModulePath>.*\.dll$</ModulePath>
            <ModulePath>.*\.exe$</ModulePath>
          </Include>
        </ModulePaths>            

      </CodeCoverage>
Brian Triplett
  • 3,462
  • 6
  • 35
  • 61