Visual Studio Code Coverage Not Showing All Assemblies
Asked Answered
C

4

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

Companionway answered 20/2, 2013 at 21:47 Comment(3)
Are the assemblies of the other projects ever loaded during the test run? If not then that would probably explain why they are not showing up.Composer
No, I don't think they are. What's the easiest way to do that? Write a test that covers at least one class?Companionway
that would probably do itComposer
C
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.

Composer answered 21/2, 2013 at 21:21 Comment(0)
C
11

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

<PropertyGroup>
     <TargetFramework>netstandard2.0</TargetFramework>
     <DebugType>Full</DebugType>
</PropertyGroup>
Conjugation answered 20/3, 2019 at 17:49 Comment(2)
Had this issue with VS Enterprise 2017, this fixed it.Paradis
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!!Kendrick
R
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);
                }
            };
        }
Ruthenium answered 7/3, 2023 at 23:57 Comment(0)
A
-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>
Aeromarine answered 5/9, 2013 at 19:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.