您可以使用Coverlet来获取.NET Framework项目中的代码覆盖率数据吗? [英] Can you use Coverlet to get code coverage data in a .NET Framework project?

查看:98
本文介绍了您可以使用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(请参阅

Create a .runsettings file and configure Coverlet in the .runsettings (see https://github.com/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项目中的代码覆盖率数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆