[英]How to exclude MVC Razor view from code coverage?
I want to exclude MVC views—ie, cshtml
files, which have C# code—from code the coverage report in ADO.我想从 ADO 中的覆盖率报告代码中排除 MVC 视图(即具有 C# 代码的
cshtml
文件)。
What I have tried is:我试过的是:
Adding the [ExcludeFromCodeCoverage]
attribute to the cshtml
.将
[ExcludeFromCodeCoverage]
属性添加到cshtml
。
Adding exclusion for the *.Views
assembly in the runsettings
file:在
runsettings
文件中为*.Views
程序集添加排除项:
<ModulePath>.*Views.*</ ModulePath>
Neither worked.都没有用。 Is there any way of achieving this?
有什么办法可以做到这一点?
Once I was able to get the runsettings
file recognized ( https://learn.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?msclkid=14b6671abb6811ec9283acde13b7ff4e&view=vs-2022#specify-a-run-settings-file-in-the-ide ), I was able to use this to exclude views that were being pre-compiled:一旦我能够识别运行设置文件(
runsettings
://learn.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?msclkid=14b6671abb6811ec9283acde13b7ff4e&view =vs-2022#specify-a-run-settings-file-in-the-ide ),我能够使用它来排除正在预编译的视图:
<?xml version="1.0" encoding="utf-8"?>
<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>
<!-- Make sure we include all the project source -->
<ModulePath>.*your.project.library.name.dll</ModulePath>
<ModulePath>.*your.project.name.dll</ModulePath>
</Include>
</ModulePaths>
<Sources>
<Exclude>
<Source>.*cshtml.*</Source> <!-- Ignore the pre-compiled views for code coverage -->
</Exclude>
</Sources>
<!-- We recommend you do not change the following values: -->
<UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
<CollectFromChildProcesses>True</CollectFromChildProcesses>
<CollectAspDotNet>False</CollectAspDotNet>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.