如何从代码覆盖率中排除 MVC Razor 视图?

发布于 2025-01-17 14:54:49 字数 405 浏览 2 评论 0原文

我想排除MVC视图 - IE,cshtml具有C#代码的文件 - 从代码ADO中的覆盖范围报告。

我尝试过的是:

  1. 添加[uble fromcodecoverage]属性属性到cshtml

  2. *。视图 runsettings文件中添加排除范围:

     < modulepath>。*视图。*</ modulepath>
     

两项工作。有什么方法可以实现这一目标吗?

I want to exclude MVC views—i.e., cshtml files, which have C# code—from code the coverage report in ADO.

What I have tried is:

  1. Adding the [ExcludeFromCodeCoverage] attribute to the cshtml.

  2. Adding exclusion for the *.Views assembly in the runsettings file:

    <ModulePath>.*Views.*</ ModulePath>
    

Neither worked. Is there any way of achieving this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情何以堪。 2025-01-24 14:54:49

一旦我能够识别 runsettings 文件(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),我能够使用它来排除正在预编译的视图:

<?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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文