简体   繁体   English

如何在VSTS(CI)中为.NET标准库(2.0)项目启用代码覆盖率

[英]How do I enable Code Coverage for .NET Standard Library (2.0) project in VSTS (CI)

Please help me - How do I enable/show code coverage result for .NET Standard library project (2.0) in VSTS (CI). 请帮助我 - 如何在VSTS(CI)中启用/显示.NET标准库项目(2.0)的代码覆盖率结果。 Have enable Test result through dotnet Test task (.NET Core 2.0 preview) and able to to see the passed Test cases. 通过dotnet测试任务 (.NET Core 2.0预览版)启用测试结果并能够查看传递的测试用例。 Next step I have added "publish result" task but it's showing the below warning during Build - No test result files matching _temp* / .trx were found . 下一步我添加了“发布结果”任务,但它在构建期间显示以下警告 - 未找到 与_temp * / .trx 匹配的测试结果文件 Even I have modified the .csproj file and added <DebugType>Full</DebugType> . 甚至我修改了.csproj文件并添加了<DebugType>Full</DebugType>

Using Visual Studio 2017 Professional (version - 15.5.2) Project - .NET Standard Library (2.0) Unit Test - MSTest (inbuilt in Visual Studio) 使用Visual Studio 2017 Professional(版本 - 15.5.2)项目 - .NET标准库(2.0)单元测试 - MSTest(内置于Visual Studio中)

What tasks / how tasks should I need to add/modify in Build Definition in VSTS, so that I can see Code Coverage against Unit Testing. 在VSTS的Build Definition中我需要添加/修改哪些任务/如何执行任务,以便我可以看到针对单元测试的代码覆盖率。

Tasks for Code Coverage - TestAssemblies 代码覆盖的任务 - TestAssemblies

other option 其他选择

Now I am able to see the Code Coverage (not sure whether correct code coverage is showing or not) but the tasks - Test Assemblies ***.test*.dll is failing with the below error - Code-Coverage-Result 现在我能够看到代码覆盖率(不确定是否显示正确的代码覆盖率)但任务 - 测试程序集***。test * .dll失败并出现以下错误 - 代码覆盖率 - 结果

  • No test is available in .........$(BuildConfiguration)\\netcoreapp2.0\\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll. 在......... $(BuildConfiguration)\\ netcoreapp2.0 \\ Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll中没有可用的测试。 Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate and try again. 确保测试项目具有包“Microsoft.NET.Test.Sdk”的nuget引用,框架版本设置是合适的,然后重试。

    • No test is available in ...... $(BuildConfiguration)\\netcoreapp2.0\\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll. 没有测试可用于...... $(BuildConfiguration)\\ netcoreapp2.0 \\ Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll。 Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate and try again. 确保测试项目具有包“Microsoft.NET.Test.Sdk”的nuget引用,框架版本设置是合适的,然后重试。

Thanks. 谢谢。

Regards, Deb 问候,Deb

First, make sure you can get code coverage result through Visual Studio. 首先,确保您可以通过Visual Studio获得代码覆盖率结果。 As far as I know, Enterprise version is required (You can use Hosted VS 2017 agent). 据我所知,企业版是必需的(您可以使用Hosted VS 2017代理商)。

The Code Coverage for .Net Core Unit test project: .Net核心单元测试项目的代码覆盖范围:

  1. Add <DebugType>Full</DebugType> to PreopertyGroup <DebugType>Full</DebugType>到PreopertyGroup

Sample: 样品:

<PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>

    <IsPackable>false</IsPackable>
    <DebugType>Full</DebugType>
  </PropertyGroup>
  1. Install Microsoft.CodeCoverage package to test project 安装Microsoft.CodeCoverage包以测试项目

Secondly, you can run test through Visual Studio Test task: ( 其次,您可以通过Visual Studio Test任务运行测试:(

Path to vstest.console.exe: C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe vstest.console.exe的路径: C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe

Check Code coverage enabled option 检查Code coverage enabled选项

Other console options: /framework:".NETCoreApp,Version=v2.0" ) 其他控制台选项:/ /framework:".NETCoreApp,Version=v2.0" :“. /framework:".NETCoreApp,Version=v2.0"

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Visual Studio 中从我的 .NET 框架项目中定位 .NET 标准 2.0? - How do I target .NET Standard 2.0 from my .NET Framework project in Visual Studio? 如何将.NET标准库打包/发布到私有VSTS Nuget订阅源? - How to pack/publish a .NET Standard Library to a private VSTS Nuget feed? 代码覆盖率:.NET代码覆盖率和SonarQube VSTS集成 - Code Coverage: .NET Code Coverage and SonarQube VSTS Integration Serilog Seq 包未安装在 .NET Standard 2.0 库项目上 - Serilog Seq package does not install on .NET Standard 2.0 library project 如何使用VSTS构建包含.NET Standard项目和.NET 4.7项目的.NET解决方案? - How to use VSTS to build a .NET solution that contains a .NET Standard project and a .NET 4.7 project? 如何创建针对.NET 2.0和.NET Standard的库? - How to create a library that targets both .NET 2.0 and .NET Standard? 如何将 PCL 转换为 .Net 标准库 - How do I convert a PCL to a .Net Standard library .NET 4.6.1项目引用的.NET Standard 2.0库-引用的图形库版本错误 - .NET Standard 2.0 library referenced by .NET 4.6.1 project - Wrong version of Drawing library referenced 如何使用.NET Standard 2.0作为目标框架创建F#库? - How to create an F# library with target framework as .NET Standard 2.0? 添加.NET Standard 2.0类库项目后,UWP应用程序项目出错 - UWP app project gets error after addition of .NET Standard 2.0 class library project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM