Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude Projects with names ending in ".Test" from my code coverage analysis in VS2012 Unit Tests

My solution is set up with projects called "ProjectName" with "ProjectName".Tests containing my unit tests. I'd like to exclude the test projects from the code coverage analysis under VS 2012 (MS Test) and have successfully managed to do this by adding the ExcludeFromCodeCoverage attribute to each test class as described here.

As the number of tests classes is growing it would be nice to exclude the entire Test assemblies. I want to use the .runsettings file also described in that MSDN link but don't seem to be having any luck.

Here is my .runsettings file:

<?xml version="1.0" encoding="utf-8"?> <RunSettings>   <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>               <Exclude>                 <ModulePath>.*tests.*</ModulePath>                 <ModulePath>.*Tests.*</ModulePath>>               </Exclude>             </ModulePaths>           </CodeCoverage>         </Configuration>       </DataCollector>     </DataCollectors>   </DataCollectionRunSettings> </RunSettings> 

This results in Empty results generated for Code Coverage, if I comment out the whole <Exclude> block I get code coverage across all of the solution's projects including the Tests (as expected, I just wanted to ensure that the addition of the runSettings file wasn't causing issues itself).

I have tried adding in:

<Include>   <ModulePath>.*\.dll$</ModulePath>   <ModulePath>.*\.exe$</ModulePath> </Include> 

But again, I get Empty Results. I was under the impression that an empty (or non-existent) Include block will include everything by default unless matched by the Exclude block, so I don't think this is strictly required.

Can anyone point me in the right direction? I see from this other question that I'm not alone in trying to exclude tests, but I would like to do it at assembly level and MSDN seems to suggest I can.

like image 764
Dutts Avatar asked Aug 29 '13 10:08

Dutts


People also ask

How do you exclude projects from code coverage?

To exclude test code from the code coverage results and only include application code, add the ExcludeFromCodeCoverageAttribute attribute to your test class. To include assemblies that aren't part of your solution, obtain the . pdb files for these assemblies and copy them into the same folder as the assembly .


1 Answers

There is a connection with the period issue as it was mentioned here. If you change the exclude section to this

<ModulePath>.*tests.dll</ModulePath> <ModulePath>.*Tests.dll</ModulePath> 

or this

<ModulePath>.*\.tests\..*</ModulePath> <ModulePath>.*\.Tests\..*</ModulePath> 

it'll work

like image 92
Grin Avatar answered Sep 29 '22 17:09

Grin