我正在使用 .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>
长类名只是每个类的完整路径的点符号。它说使用 \.
来分隔 namespace 。
我的一门类(class)的示例是:
namespace xxx.DI.Mobile.Core.State.ViewModels.xxx
{
public class xxx : yyy
{
然后将其放入函数标签中,如下所示:
<Function>xxx.DI.Mobile.Core.State.ViewModels.xxx.xxx</Function>
在我的函数标签中尝试这些正则表达式,但还没有起作用:
<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>
标签排除函数。因此,要排除整个类(class),只需添加 \..*
到类(class)结束 - 其中 \.
表示点和 .*
意味着任何事情。例如类的所有函数。示例:
<Function>xxx.xxx.Mobile.Core.xxx.ViewModels.Vehicle.xxx\..*</Function>
尽管点的意思是 \.
,只有 .
无论如何,我的文件夹名称之间的关系都有效。
关于c# - 从代码覆盖率中排除类 - .runsettings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40368548/