【问题标题】:Problem code coverage in Azure Devops VS test task. .Coverage not createdAzure Devops VS 测试任务中的问题代码覆盖率。 .Coverage 未创建
【发布时间】:2020-02-01 02:43:09
【问题描述】:

我正在尝试在 Azure DevOps 中创建一个包含“vs 测试任务”的构建管道。这里没有什么花哨的。我想获得代码覆盖率以将其发送到 sonaQube。但是,管道完成任务后,并没有创建 .Coverage 文件。

有一些错误可能是问题,但我不确定。 有一个很大的“数据收集:找不到数据收集器'代码覆盖率'”,这可能与我的 UnitTestProject.dll 是为框架 4.6.2 和平台 AnyCPU 构建的事实有关(对于这个问题,我试图强制: otherConsoleOptions:/Framework:NETFramework,Version=v4.6.2')。

我的代理在 Windows server 2012 和 Visual Studio Enterprise 上运行,一切都是最新的: VS version

[命令]“C:\Program Files (x86)\Microsoft VisualStudio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe”@C:\Agent_AzureDevOps_1_work_temp\22f8bb11-e53e-11e9 -95d5-5bdab8c29281.txt Microsoft (R) 测试执行命令行工具版本 15.9.0

我的 .trx 文件已创建,但是我的 .coverage 文件无处可见。 我确保已启用代码覆盖率。

我的包包含那些 NuGet NuGet in my package.config

如果你们有想法,我被屏蔽了,不知道该去哪里找。

感谢您的时间。如果你们想了解更多信息,请不要犹豫。

【问题讨论】:

  • 日志清楚地显示“找不到数据收集器:代码覆盖率”。您对此进行了任何故障排除吗?这是私人代理还是您使用的是 Microsoft 托管代理?如果是私人代理,您是否确认已安装适当的 Visual Studio SKU 以允许收集代码覆盖率?
  • 它是托管在 Windows Server 2012 上的私有代理。
  • VSTests - 找不到诊断数据适配器“代码覆盖率”。我检查了这篇文章,没有。它不是重复的。
  • 那么你的构建服务器上安装了VS Enterprise?

标签: azure-devops code-coverage vstest


【解决方案1】:

我没有足够的声誉来添加评论,所以我希望这篇文章不要被删除(虽然我认为这不是一个直接的答案)。我想向您提出以下建议:

您是否有自己的 *.runsettings 文件(您可能在其中指定了特定条目?如果您没有自己指定 *.runsettings 文件,Azure DevOps vstest@2 任务将使用“默认”运行设置文件. 至少这是我在日志中能观察到的(debug=true)

希望对你有帮助

BR迈克尔

【讨论】:

    【解决方案2】:

    我也有类似的问题。我运行这个命令:

    >dotnet test --logger trx "--collect:Code Coverage"
      Determining projects to restore...
      All projects are up-to-date for restore.
      MyAPI -> ...\MyApi\bin\Debug\net47\MyAPI.exe
      MyAPI.Tests -> ...\MyAPI.Tests\bin\Debug\net47\MyAPI.Tests.dll
    Warning: Update the Microsoft.NET.Test.Sdk package reference to version 15.8.0 or later to collect code coverage.
    Test run for ...\MyAPI.Tests\bin\Debug\net47\MyAPI.Tests.dll (.NETFramework,Version=v4.7)
    Microsoft (R) Test Execution Command Line Tool Version 16.10.0
    Copyright (c) Microsoft Corporation.  All rights reserved.
    
    Starting test execution, please wait...
    A total of 1 test files matched the specified pattern.
    Data collection : Unable to find a datacollector with friendly name 'Code Coverage'.
    Data collection : Could not find data collector 'Code Coverage'
    Results File: ...\MyAPI.Tests\TestResults\***_2021-09-03_12_02_21.trx
    
    Passed!  - Failed:     0, Passed:    22, Skipped:     0, Total:    22, Duration: 201 ms - MyAPI.Tests.dll (net47)
    

    .trx 是生成的,但不是 .coverage。

    解决方法是在测试项目中添加NuGet包Microsoft.NET.Test.Sdk

    【讨论】:

      猜你喜欢
      • 2020-04-29
      • 2020-10-05
      • 1970-01-01
      • 1970-01-01
      • 2021-08-13
      • 2013-04-16
      • 1970-01-01
      • 2020-05-22
      • 2020-07-08
      相关资源
      最近更新 更多