首页 文章

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

提问于
浏览
2

请帮助我 - 如何在VSTS(CI)中启用/显示.NET标准库项目(2.0)的代码覆盖率结果 . 通过 dotnet Test task (.NET Core 2.0预览)启用测试结果,并能够查看传递的测试用例 . 下一步我添加了"publish result"任务,但它在Build - No test result files matching _temp/.trx were found* 期间显示以下警告 . 即使我修改了.csproj文件并添加了 <DebugType>Full</DebugType> .

使用Visual Studio 2017 Professional(版本 - 15.5.2)项目 - .NET标准库(2.0)单元测试 - MSTest(内置于Visual Studio中)

我需要在VSTS的Build Definition中添加/修改哪些任务/如何执行任务,以便我可以看到针对单元测试的代码覆盖率 .

代码覆盖的任务 - TestAssemblies

other option

现在我能够看到代码覆盖率(不确定是否显示正确的代码覆盖率)但任务 - 测试程序集*** . test * .dll失败并出现以下错误 - Code-Coverage-Result

  • ......... $(BuildConfiguration)\ netcoreapp2.0 \ Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll中没有可用的测试 . 确保测试项目具有包“Microsoft.NET.Test.Sdk”的nuget引用,框架版本设置是合适的,然后重试 .

  • 没有测试可用于...... $(BuildConfiguration)\ netcoreapp2.0 \ Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll . 确保测试项目具有包"Microsoft.NET.Test.Sdk"的nuget引用,并且框架版本设置是合适的,然后重试 .

谢谢 .

问候,Deb

1 回答

  • 3

    首先,确保您可以通过Visual Studio获得代码覆盖率结果 . 据我所知,企业版是必需的(您可以使用Hosted VS 2017代理商) .

    .Net核心单元测试项目的代码覆盖范围:

    • <DebugType>Full</DebugType> 添加到PreopertyGroup

    样品:

    <PropertyGroup>
        <TargetFramework>netcoreapp2.0</TargetFramework>
    
        <IsPackable>false</IsPackable>
        <DebugType>Full</DebugType>
      </PropertyGroup>
    

    其次,您可以通过Visual Studio Test任务运行测试:(

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

    检查 Code coverage enabled 选项

    其他控制台选项: /framework:".NETCoreApp,Version=v2.0"

    enter image description here

相关问题