您可以使用Coverlet来获取.NET Framework项目中的代码覆盖率数据吗?

编程入门 行业动态 更新时间:2024-10-12 08:22:56
本文介绍了您可以使用Coverlet来获取.NET Framework项目中的代码覆盖率数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个大型的.NET Framework解决方案,并且希望开始收集代码覆盖率数据作为构建管道的一部分(以及在我们本地的开发人员机器上).

I have a large .NET Framework solution and want to start collecting code coverage data as part of our build pipeline (as well as on our local developer machines).

在Coverlet GitHub页面上,它说它支持.NET Framework项目,但是所有示例都使用 dotnet test CLI命令.

On the Coverlet GitHub page it says that it supports .NET Framework projects but all the examples are using the dotnet test CLI command.

是否可以为此使用Coverlet,还是应该查看OpenCover之类的东西?

Is it possible to use Coverlet for this or should I be looking at something like OpenCover?

推荐答案

选项1

  • 使用任务 Visual Studio测试

创建一个.runsettings文件并在.runsettings中配置Coverlet(请参阅 github/tonerdo/coverlet/blob/master/Documentation/VSTestIntegration.md#coverlet-options-supported by-vstest-integration )

Create a .runsettings file and configure Coverlet in the .runsettings (see github/tonerdo/coverlet/blob/master/Documentation/VSTestIntegration.md#coverlet-options-supported-by-vstest-integration)

参考任务中的.runsettings文件

Reference the .runsettings file in the task

勾选选项启用代码覆盖率

如果这不起作用,请使用发布代码覆盖率结果任务来发布由管理员生成的corbertura文件(默认名称: coverage.cobertura.xml ).测试任务

If this doesn't work, use a Publish code coverage results task, to publish the corbertura file (default name: coverage.cobertura.xml) produced by the test task

选项2

  • 将以下NuGet软件包添加到您的测试项目中
    • coverlet.msbuild
    • Microsoft.NET.Test.Sdk
    • Microsoft.TestPlatform
    • Microsoft.TestPlatform.Build
    <PropertyGroup> <VSTestTaskAssemblyFile>$(MSBuildThisFileDirectory)\..\packages\Microsoft.TestPlatform.Build.16.6.1\lib\netstandard2.0\Microsoft.TestPlatform.Build.dll</VSTestTaskAssemblyFile> <VSTestConsolePath>$(MSBuildThisFileDirectory)..\packages\Microsoft.TestPlatform.Portable.16.6.1\tools\netcoreapp2.1\vstest.console.dll</VSTestConsolePath> <CoverletOutputFormat>cobertura</CoverletOutputFormat> </PropertyGroup>

    • 使用 MSBuild 任务
      • 使用以下命令行参数: < your-project> .csproj/p:CollectCoverage = true/t:VSTest

更多推荐

您可以使用Coverlet来获取.NET Framework项目中的代码覆盖率数据吗?

本文发布于:2023-11-14 22:09:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1588626.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:您可以   覆盖率   代码   项目   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!