为什么自定义 runsettings 文件 returns 的代码覆盖排除了路径
Why code coverage on custom runsettings file returns excluded paths
在 Azure Devops 中,我使用了带有过滤器的自定义运行设置来匹配包含文本 Xpand.XAF.Modules
的所有程序集。但是我得到的结果包括我过滤掉的路径。
这是我的运行设置文件
Updated Run Settings:
<!-- File name extension must be .runsettings -->
<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>
<Include>
<ModulePath>.*Xpand.XAF.Modules.*\.dll$</ModulePath>
</Include>
<Exclude>
<ModulePath>.*Tests.dll</ModulePath>
<ModulePath>.*Hub.*</ModulePath>
</Exclude>
</ModulePaths>
<Functions>
<Exclude>
<!-- Exclude methods in a class or namespace named UnitTest: -->
<Function>.*\.Source\..*</Function>
</Exclude>
</Functions>
<!-- We recommend you do not change the following values: -->
<!-- Set this to True to collect coverage information for functions marked with the "SecuritySafeCritical" attribute. Instead of writing directly into a memory location from such functions, code coverage inserts a probe that redirects to another function, which in turns writes into memory. -->
<UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
<!-- When set to True, collects coverage information from child processes that are launched with low-level ACLs, for example, UWP apps. -->
<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
<!-- When set to True, collects coverage information from child processes that are launched by test or production code. -->
<CollectFromChildProcesses>True</CollectFromChildProcesses>
<!-- When set to True, restarts the IIS process and collects coverage information from it. -->
<CollectAspDotNet>False</CollectAspDotNet>
</CodeCoverage>
</Configuration>
</DataCollector>
<DataCollector friendlyName="blame" enabled="True" />
</DataCollectors>
</DataCollectionRunSettings>
<RunConfiguration>
<BatchSize>1000</BatchSize>
<ResultsDirectory>d:\a\_temp\TestResults</ResultsDirectory>
</RunConfiguration>
<LoggerRunSettings>
<Loggers>
<Logger friendlyName="blame" enabled="True" />
</Loggers>
</LoggerRunSettings>
</RunSettings>
我得到的结果有 xunit、nunit 等条目
+ nunit3.testadapter.dll 1253 52.10% 1152 47.90%
+ system.interactive.dll 1233 95.43% 59 4.57%
+ system.reactive.dll 40510 91.69% 3671 8.31%
+ testslib.dll 55 12.56% 383 87.44%
+ xpand.source.extensions.dll 82 64.06% 46 35.94%
+ xpand.xaf.modules.autocommit.dll 37 32.74% 76 67.26%
+ xpand.xaf.modules.clonemembervalue.dll 12 7.06% 158 92.94%
+ xpand.xaf.modules.clonemodelview.dll 31 32.98% 63 67.02%
+ xpand.xaf.modules.gridlisteditor.dll 3 3.13% 93 96.88%
解决方案
虽然接受的答案不是确切的解决方案,但它让我明白更积极的过滤可能会起作用,所以我修改了我的 runsettings 文件,为额外的程序集添加了明确的过滤器并起作用。
<ModulePaths>
<Include>
<ModulePath>.*Xpand\.XAF\.Modules.*\.dll$</ModulePath>
</Include>
<Exclude>
<ModulePath>.*Tests\.dll</ModulePath>
<ModulePath>.*Hub.*</ModulePath>
<ModulePath>.*system.*</ModulePath>
<ModulePath>.*xunit.*</ModulePath>
<ModulePath>.*nunit.*</ModulePath>
<ModulePath>.*xpand\.source.*</ModulePath>
<ModulePath>.*testslib.*</ModulePath>
</Exclude>
</ModulePaths>
<Functions>
<Exclude>
<!-- Exclude methods in a class or namespace named UnitTest: -->
<Function>.*\.Source\..*</Function>
</Exclude>
</Functions>
我不能说你排除的路径到底有什么问题,但我知道语法非常精巧。例如。点必须用斜杠转义,模式匹配类似于正则表达式。我们对 .Tests.dll
个文件进行了相同的排除,这在我们的案例中有效:
<Exclude>
<ModulePath>.*Tests\.dll$</ModulePath>
</Exclude>
在 Azure Devops 中,我使用了带有过滤器的自定义运行设置来匹配包含文本 Xpand.XAF.Modules
的所有程序集。但是我得到的结果包括我过滤掉的路径。
这是我的运行设置文件
Updated Run Settings:
<!-- File name extension must be .runsettings -->
<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>
<Include>
<ModulePath>.*Xpand.XAF.Modules.*\.dll$</ModulePath>
</Include>
<Exclude>
<ModulePath>.*Tests.dll</ModulePath>
<ModulePath>.*Hub.*</ModulePath>
</Exclude>
</ModulePaths>
<Functions>
<Exclude>
<!-- Exclude methods in a class or namespace named UnitTest: -->
<Function>.*\.Source\..*</Function>
</Exclude>
</Functions>
<!-- We recommend you do not change the following values: -->
<!-- Set this to True to collect coverage information for functions marked with the "SecuritySafeCritical" attribute. Instead of writing directly into a memory location from such functions, code coverage inserts a probe that redirects to another function, which in turns writes into memory. -->
<UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
<!-- When set to True, collects coverage information from child processes that are launched with low-level ACLs, for example, UWP apps. -->
<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
<!-- When set to True, collects coverage information from child processes that are launched by test or production code. -->
<CollectFromChildProcesses>True</CollectFromChildProcesses>
<!-- When set to True, restarts the IIS process and collects coverage information from it. -->
<CollectAspDotNet>False</CollectAspDotNet>
</CodeCoverage>
</Configuration>
</DataCollector>
<DataCollector friendlyName="blame" enabled="True" />
</DataCollectors>
</DataCollectionRunSettings>
<RunConfiguration>
<BatchSize>1000</BatchSize>
<ResultsDirectory>d:\a\_temp\TestResults</ResultsDirectory>
</RunConfiguration>
<LoggerRunSettings>
<Loggers>
<Logger friendlyName="blame" enabled="True" />
</Loggers>
</LoggerRunSettings>
</RunSettings>
我得到的结果有 xunit、nunit 等条目
+ nunit3.testadapter.dll 1253 52.10% 1152 47.90%
+ system.interactive.dll 1233 95.43% 59 4.57%
+ system.reactive.dll 40510 91.69% 3671 8.31%
+ testslib.dll 55 12.56% 383 87.44%
+ xpand.source.extensions.dll 82 64.06% 46 35.94%
+ xpand.xaf.modules.autocommit.dll 37 32.74% 76 67.26%
+ xpand.xaf.modules.clonemembervalue.dll 12 7.06% 158 92.94%
+ xpand.xaf.modules.clonemodelview.dll 31 32.98% 63 67.02%
+ xpand.xaf.modules.gridlisteditor.dll 3 3.13% 93 96.88%
解决方案
虽然接受的答案不是确切的解决方案,但它让我明白更积极的过滤可能会起作用,所以我修改了我的 runsettings 文件,为额外的程序集添加了明确的过滤器并起作用。
<ModulePaths>
<Include>
<ModulePath>.*Xpand\.XAF\.Modules.*\.dll$</ModulePath>
</Include>
<Exclude>
<ModulePath>.*Tests\.dll</ModulePath>
<ModulePath>.*Hub.*</ModulePath>
<ModulePath>.*system.*</ModulePath>
<ModulePath>.*xunit.*</ModulePath>
<ModulePath>.*nunit.*</ModulePath>
<ModulePath>.*xpand\.source.*</ModulePath>
<ModulePath>.*testslib.*</ModulePath>
</Exclude>
</ModulePaths>
<Functions>
<Exclude>
<!-- Exclude methods in a class or namespace named UnitTest: -->
<Function>.*\.Source\..*</Function>
</Exclude>
</Functions>
我不能说你排除的路径到底有什么问题,但我知道语法非常精巧。例如。点必须用斜杠转义,模式匹配类似于正则表达式。我们对 .Tests.dll
个文件进行了相同的排除,这在我们的案例中有效:
<Exclude>
<ModulePath>.*Tests\.dll$</ModulePath>
</Exclude>