简体   繁体   English

从代码覆盖范围中排除类-.runsettings

[英]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. 我正在使用.runsettings文件将某些代码从代码覆盖率中排除,但并未将它们从代码覆盖率中排除,因为我的代码覆盖率百分比没有任何变化。 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. 长类名只是每个类完整路径的DOT表示法。 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? 为什么不将我的任何代码排除在代码范围之外?

The <Function> tag excludes functions. <Function>标签不包括功能。 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. 无论我上面的文件夹名称之间的工作。

My guess is system is unable to interpret <function> block in exclude, may be try giving regular expression. 我的猜测是系统无法解释排除中的<function>块,可能是尝试给出正则表达式。

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 anystring.test.dll

and

anystring.csv.dll 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 $匹配字符串的结尾

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM