通过 .runsettings 从代码覆盖率中排除 Blazor 页面

发布于 2025-01-13 13:30:34 字数 1573 浏览 3 评论 0原文

我有这个小 Blazor 应用程序。现在,我想通过 .runsettings 从代码覆盖率中排除所有 Blazor 页面。这些页面位于 /RaspiFanController/Pages/ 下。我的测试使用 NUnit,覆盖率计算使用 coverlet。

我已经尝试使用以下内容创建文件 /Tests/.runsettings

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
    <!-- Configurations for data collectors -->
    <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>
                        <Functions>
                            <Exclude>
                                <Function>.*Pages.*</Function>
                            </Exclude>
                        </Functions>
                    </CodeCoverage>
                </Configuration>
            </DataCollector>
        </DataCollectors>
    </DataCollectionRunSettings>
</RunSettings>

不幸的是,代码覆盖率仍然包含 Blazor 页面 - 都在 JetBrains Rider 中并通过 dotnet test --收集:“XPlat 代码覆盖率”

编辑:我不一定要通过 .runsettings 解决这个问题。如果可以通过csproj我也很好

I have this little Blazor application. Now I'd like to exclude all Blazor pages from code coverage via .runsettings. The pages are located under /RaspiFanController/Pages/. My tests are using NUnit and the coverage calculation uses coverlet.

I've already tried to create the file /Tests/.runsettings with the following content:

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
    <!-- Configurations for data collectors -->
    <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>
                        <Functions>
                            <Exclude>
                                <Function>.*Pages.*</Function>
                            </Exclude>
                        </Functions>
                    </CodeCoverage>
                </Configuration>
            </DataCollector>
        </DataCollectors>
    </DataCollectionRunSettings>
</RunSettings>

Unfortunately, the code coverage still contains the Blazor pages - both within JetBrains Rider and via dotnet test --collect:"XPlat Code Coverage".

Edit: I'm not bound to solve this via .runsettings. If it is possible via csproj I'm also fine ????

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

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

发布评论

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

评论(1

毁我热情 2025-01-20 13:30:34

.runsettings 文件必须如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
    <DataCollectionRunSettings>
        <DataCollectors>
            <DataCollector friendlyName="XPlat code coverage">
                <Configuration>
                    <ExcludeByFile>**/*.razor,</ExcludeByFile>
                </Configuration>
            </DataCollector>
        </DataCollectors>
    </DataCollectionRunSettings>
</RunSettings>

在我的例子中,我必须将此文件显式传递给 dotnet test,因此命令如下所示:
dotnet test --collect:"XPlat Code Coverage" --no-restore --settings coverlet.runsettings

不幸的是,JetBrains Rider/dotCover 在计算代码覆盖率时不遵循这些设置。

The .runsettings file has to look like this:

<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
    <DataCollectionRunSettings>
        <DataCollectors>
            <DataCollector friendlyName="XPlat code coverage">
                <Configuration>
                    <ExcludeByFile>**/*.razor,</ExcludeByFile>
                </Configuration>
            </DataCollector>
        </DataCollectors>
    </DataCollectionRunSettings>
</RunSettings>

In my case I had to pass this file explicitly to dotnet test, so the command looks like this:
dotnet test --collect:"XPlat Code Coverage" --no-restore --settings coverlet.runsettings

Unfortunately, JetBrains Rider/dotCover does not honor these settings when calculating the code coverage.

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