从代码覆盖范围中排除 class - .runsettings
Exclude class from code coverage - .runsettings
我正在使用 .runsettings 文件从代码覆盖范围中排除一些代码,但它并没有从代码覆盖范围中排除它们,因为我的代码覆盖百分比根本没有改变。也没有错误。
代码:
<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>
长 class 名称只是每个 class 的完整路径的点符号。它说使用 \.
来分隔名称空间。
我的 classes 之一的例子是:
namespace xxx.DI.Mobile.Core.State.ViewModels.xxx
{
public class xxx : yyy
{
然后像这样进入函数标签:
<Function>xxx.DI.Mobile.Core.State.ViewModels.xxx.xxx</Function>
在我的函数标签中尝试使用这些正则表达式,但 none 还有效:
<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>
为什么不从代码覆盖范围中排除我的任何代码?
我的猜测是系统无法解释排除中的 <function>
块,可以尝试给出正则表达式。
请尝试以下:
<Function>^xxx\.DI\.Mobile\.Core\.State\.ViewModels\.Common\.GetAQuoteViewModel$</Function>
或
<Function>.*\.DI\.Mobile\.Core\.State\.ViewModels\.Common\.GetAQuoteViewModel$</Function>
此外,前两个排除被解释为
anystring.test.dll
和
anystring.csv.dll
希望你能接受。
我想你已经知道规则,特定于此代码覆盖率设置。
但在下面列出。
.* 匹配任意字符的字符串
。匹配点“.”
( ) 匹配括号“( )”
\ 匹配文件路径分隔符“\”
^ 匹配字符串的开头
$ 匹配字符串的结尾
<Function>
标签排除函数。因此,要排除整个 class,只需将 \..*
添加到 class 的末尾 - 其中 \.
表示点,.*
表示任何内容。例如class的所有函数。示例:
<Function>xxx.xxx.Mobile.Core.xxx.ViewModels.Vehicle.xxx\..*</Function>
尽管点本应是 \.
,但我的文件夹名称之间只有一个 .
无论如何都可以正常工作。
我正在使用 .runsettings 文件从代码覆盖范围中排除一些代码,但它并没有从代码覆盖范围中排除它们,因为我的代码覆盖百分比根本没有改变。也没有错误。
代码:
<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>
长 class 名称只是每个 class 的完整路径的点符号。它说使用 \.
来分隔名称空间。
我的 classes 之一的例子是:
namespace xxx.DI.Mobile.Core.State.ViewModels.xxx
{
public class xxx : yyy
{
然后像这样进入函数标签:
<Function>xxx.DI.Mobile.Core.State.ViewModels.xxx.xxx</Function>
在我的函数标签中尝试使用这些正则表达式,但 none 还有效:
<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>
为什么不从代码覆盖范围中排除我的任何代码?
我的猜测是系统无法解释排除中的 <function>
块,可以尝试给出正则表达式。
请尝试以下:
<Function>^xxx\.DI\.Mobile\.Core\.State\.ViewModels\.Common\.GetAQuoteViewModel$</Function>
或
<Function>.*\.DI\.Mobile\.Core\.State\.ViewModels\.Common\.GetAQuoteViewModel$</Function>
此外,前两个排除被解释为
anystring.test.dll
和
anystring.csv.dll
希望你能接受。
我想你已经知道规则,特定于此代码覆盖率设置。
但在下面列出。
.* 匹配任意字符的字符串
。匹配点“.”
( ) 匹配括号“( )”
\ 匹配文件路径分隔符“\”
^ 匹配字符串的开头
$ 匹配字符串的结尾
<Function>
标签排除函数。因此,要排除整个 class,只需将 \..*
添加到 class 的末尾 - 其中 \.
表示点,.*
表示任何内容。例如class的所有函数。示例:
<Function>xxx.xxx.Mobile.Core.xxx.ViewModels.Vehicle.xxx\..*</Function>
尽管点本应是 \.
,但我的文件夹名称之间只有一个 .
无论如何都可以正常工作。