【问题标题】:Creating a test report with Azure Pipelines and Coverlet does not create the coverage.opencover.xml file使用 Azure Pipelines 和 Coverlet 创建测试报告不会创建 coverage.opencover.xml 文件
【发布时间】:2019-12-25 12:00:48
【问题描述】:

这是我的解决方案结构:

.
├── Application
├── Application.Core
├── Application.Domain
└── Application.UnitTests -> HAS codecov 1.9.0 NuGet package installed

构建脚本工作正常,但我无法让它在根文件夹中以coverage.opencover.xml 格式创建封面结果。

我的 azure-pipelines.yml:

trigger:
  - master

pool:
  vmImage: "vs2017-win2016"

variables:
  solution: "**/*.sln"
  buildPlatform: "Any CPU"
  buildConfiguration: "Release"

steps:
  - task: DotNetCoreCLI@2
    displayName: "Building **/*.csproj..."
    inputs:
      command: build
      projects: "**/*.csproj"
      arguments: "--configuration Release"

  - task: DotNetCoreCLI@2
    condition: succeededOrFailed()
    displayName: Testing **/*.UnitTests/*.csproj
    inputs:
      command: test
      projects: |
        **/*.UnitTests/*.csproj
      arguments: '--configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutput=$(Agent.BuildDirectory)\coverage /p:CoverletOutputFormat=opencover /p:Exclude="[*Tests]*"'
      nobuild: true

  - task: PublishTestResults@2
    condition: succeededOrFailed()
    inputs:
      testRunner: VSTest
      testResultsFiles: "**/*.opencover.xml"
  - powershell: .\codecov.ps1 -token $(CODECOV_TOKEN) $(Agent.BuildDirectory)\coverage.opencover.xml
    displayName: Upload to CodeCov.io

因此,我得到Testing **/*.UnitTests/*.csproj 任务的以下输出:

开始:测试 **/.UnitTests/.csproj ==================================================== ============================ 任务:.NET Core 描述:构建、测试、打包或 发布 dotnet 应用程序,或运行自定义 dotnet 命令版本
:2.162.0 作者:微软公司帮助: https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli ==================================================== ============================ C:\windows\system32\chcp.com 65001 活动代码页:65001 "C:\Program 文件\dotnet\dotnet.exe" 测试 d:\a\1\s\BlazorApp.UnitTests\BlazorApp.UnitTests.csproj --logger trx --results-directory d:\a_temp --configuration Release /p:CollectCoverage=true /p:CoverletOutput=d:\a\1\coverage /p:CoverletOutputFormat=opencover /p:Exclude=[Tests] 测试运行 d:\a\1\s\BlazorApp.UnitTests\bin\Release\netcoreapp3.1\BlazorApp.UnitTests.dll(.NETCoreApp,Version=v3.1) Microsoft (R) 测试执行命令行工具版本 16.3.0 版权所有 (c) 微软公司。保留所有权利。

开始测试执行,请稍候...

共有 1 个测试文件与指定的模式匹配。结果文件: d:\a_temp\VssAdministrator_fv-az74_2019-12-25_11_32_03.trx

试运行成功。总测试:1 通过:1 总时间:1.5842 秒

问题是即使yml 参数定义了应该执行的coverlet 设置,也没有创建coverage.opencover.xml 文件。如果codecov.ps1 PowerShell 脚本可以找到现在丢失的测试结果文件,它就会起作用。

【问题讨论】:

    标签: azure-pipelines codecov coverlet


    【解决方案1】:

    基本上,除非另有定义,否则默认的DotNetCoreCLI@2 任务似乎会将--results-directory d:\a_temp 参数添加到测试命令中。这似乎可以防止床单运行。

    为了兼容性,我将输出文件类型更改为cobertura,并在任务中添加了以下定义:publishTestResults: false,这似乎解决了我的问题。

      - task: DotNetCoreCLI@2
        condition: succeededOrFailed()
        displayName: Testing **/*.UnitTests/*.csproj
        inputs:
          command: test
          projects: |
            **/*.UnitTests/*.csproj
          arguments: '--configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutput=$(Agent.BuildDirectory)\coverage /p:CoverletOutputFormat=cobertura /p:Exclude="[*Tests]*"'
          nobuild: true
          publishTestResults: false
    

    【讨论】:

    • 我以类似的方式使用 Coverlet,但是当我更改为 Windows VM(来自 unbuntu)时遇到了同样的问题。我在 Azure Devops 中的覆盖率报告消失了,因为我更改了 VM 类型。我设置了nobuild: truepublishTestResults: false,它又回来了。感谢您的回答!
    【解决方案2】:

    您还可以确保您的单元测试项目包含对 coverlet.msbuild 和 OpenCover 的 NuGet 引用。我认为单独使用coverlet.msbuild 应该没问题。

    【讨论】:

      猜你喜欢
      • 2022-11-12
      • 1970-01-01
      • 2016-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-06
      • 1970-01-01
      • 2011-10-30
      相关资源
      最近更新 更多