How can I force exclusion of certain assemblies from Code Coverage?
Asked Answered
M

2

7

I'm trying to restrict the assemblies that get analyzed in the Code Coverage procedure in TFS by using a runsettings file, but some assemblies insist in being analyzed even if I exclude them explicitly.

This is my current runsettings file contents:

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
  <!-- Configurations for data collectors -->
  <DataCollectionRunSettings>
    <DataCollectors>
      <DataCollector friendlyName="Code Coverage" 
                     uri="datacollector://Microsoft/CodeCoverage/2.0" 
                     assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
        <Configuration>
          <CodeCoverage>
            <ModulePaths>
              <Include>
                <ModulePath>.*Cloud4Mobile.*</ModulePath>
              </Include>
              <Exclude>
                <ModulePath>.*Tests.dll$</ModulePath>
                <ModulePath>.*TestUtilities.dll$</ModulePath>
              </Exclude>
            </ModulePaths>
            <CompanyNames>
              <Include>.*Mobiltec.*</Include>
            </CompanyNames>
          </CodeCoverage>
        </Configuration>
      </DataCollector>
    </DataCollectors>
  </DataCollectionRunSettings>
</RunSettings>

But when I run code coverage from Visual Studio to test this file, the analysis still shows me other assemblies that do not match my filter, like AutoMapper and CacheManager:

enter image description here

Note that my settings already exclude these assemblies by default, but even then I tried to explicitly exclude them to no avail, like this:

<Exclude>
  <ModulePath>^AutoMapper.dll$</ModulePath>
  ...
</Exclude>

I tried all variations of the regex there, from the less restrictive (using .*) to the most restrictive (like that example). These assemblies are polluting the report that I get on the TFS Build summary, and I'd like to remove them from the analysis. This is the full output that I was getting from TFS, which is obviously quite useless:

enter image description here

I managed to remove most of those with this .runsettings configuration file, but how do I make sure these outliers do not show there too? Why are they even showing in the first place, considering they were not matched by my include filters at all?

Maye answered 15/5, 2015 at 22:10 Comment(0)
I
2

My guess would be that the . in Automapper.dll is causing the problem. Could you try using

<Exclude>
  <ModulePath>.*AutoMapper\.dll$</ModulePath>

For your case of excluding everything by default you should just use .*\.dll in the modulepaths exclusions.

Intine answered 16/5, 2015 at 15:10 Comment(3)
I tried that too and it also didn't work. I think I tried every possible variation of exclusions containing the word AutoMapper with the same results. As for your suggestion about excluding everything, I don't think that will work since the exclusion list is processed after the inclusion, thus nothing would be selected.Maye
@Maye Have you also tried to add this <ModulePath>.*AutoMapper.*</ModulePath> to the Exclude section/element?Liger
i need exclude test project assembly ?how to do thisEyeglass
B
0

This may seem obvious, but did you update your build definition to include the .runsettings file? It's one thing to have CodeCoverage enabled in your build, but you have to provide the path to the .runsettings file.

Blocking answered 1/12, 2015 at 23:21 Comment(2)
Yes, I was setting the runsettings file correctly in the build definition back then. Thanks for the input, but you should probably consider asking these kinds of questions in comments instead of in an answer like this.Maye
My bad. Fairly new to answering things here. Thanks for the guidance.Blocking

© 2022 - 2024 — McMap. All rights reserved.