BeniaminoBaggins
BeniaminoBaggins

Reputation: 12463

Exclude class from code coverage - .runsettings

I'm using a .runsettings file to exclude some code from code coverage but it is not excluding them from the code coverage, as my code coverage percentages are not changing at all. There are no errors either.

code:

  <CodeCoverage>
    <ModulePaths>
      <Include>
        <ModulePath>.*\.dll$</ModulePath>
      </Include>
      <Exclude>
        <ModulePath>.*\.test.dll</ModulePath>
        <ModulePath>.*\.csv.dll</ModulePath>
      </Exclude>
    </ModulePaths>
    <Functions>
        <Exclude>
            <!-- CORE -->
            <Function>xxx.DI.Mobile.Core.ViewModels.HomeAndContents.xxx</Function>
            <Function>xxx.DI.Mobile.Core.ViewModels.Components.xxxx</Function>
            <Function>xxx.DI.Mobile.Core.ViewModels.Components.xxx</Function>

            <!-- xxx -->
            <Function>^xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.xxx\.xxx$</Function>
            <Function>^xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.xxx\.xxx$</Function>
            <Function>.*\.xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.xxx\.xxx$</Function>
            <Function>.*xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.Dashboard\.xxx$</Function>
        </Exclude>
    </Functions>
    <UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
    <AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
    <CollectFromChildProcesses>True</CollectFromChildProcesses>
    <CollectAspDotNet>False</CollectAspDotNet>
  </CodeCoverage>

The long class names are just the DOT notation of the full path of each class. It says to use \. to delimit namespaces.

An example of one of my classes is:

namespace xxx.DI.Mobile.Core.State.ViewModels.xxx
{
    public class xxx : yyy
    {

then that goes in the function tag like so:

<Function>xxx.DI.Mobile.Core.State.ViewModels.xxx.xxx</Function>

Trying these regular expressions in my function tags but none have worked yet:

<Function>^xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.Vehicle\.xxx$</Function>
<Function>^xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.Vehicle\.xxx$</Function>
<Function>.*\.xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.Policies\.xxx$</Function>
<Function>.*xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.Dashboard\.xxx$</Function>
<Function>xxx\.DI\.Mobile\.Core\.xxx\.ViewModels\.Common\.xxx</Function>

Why is it not excluding any of my code from code coverage?

Upvotes: 2

Views: 9294

Answers (2)

BeniaminoBaggins
BeniaminoBaggins

Reputation: 12463

The <Function> tag excludes functions. So to exclude a whole class, just add \..* to the end of the class - where \. means dot and .* means anything. Eg all functions of the class. Example:

<Function>xxx.xxx.Mobile.Core.xxx.ViewModels.Vehicle.xxx\..*</Function>

Even though dot is meant to be \., having only a . between my folder names as above is working regardless.

Upvotes: 2

Pavan Chandaka
Pavan Chandaka

Reputation: 12781

My guess is system is unable to interpret <function> block in exclude, may be try giving regular expression.

please try below:

<Function>^xxx\.DI\.Mobile\.Core\.State\.ViewModels\.Common\.GetAQuoteViewModel$</Function> 

or

<Function>.*\\.DI\.Mobile\.Core\.State\.ViewModels\.Common\.GetAQuoteViewModel$</Function> 

And more over, the first two excludes are interpreted as

anystring.test.dll

and

anystring.csv.dll

Hope you are fine with that.

I think you know the rule already, specific to this code coverage settings.

But listing below.

.* matches a string of any characters

. matches a dot "."

( ) matches parentheses "( )"

\ matches a file path delimiter "\"

^ matches the start of the string

$ matches the end of the string

Upvotes: 0

Related Questions