I want to exclude MVC views—ie, cshtml
files, which have C# code—from code the coverage report in ADO.
What I have tried is:
Adding the [ExcludeFromCodeCoverage]
attribute to the cshtml
.
Adding exclusion for the *.Views
assembly in the runsettings
file:
<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:
<?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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.