3

这是我的解决方案结构:

.
├── 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 作者:Microsoft Corporation 帮助: https ://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli ==================================================== ============================= C:\windows\system32\chcp.com 65001 活动代码页:65001 "C:\Program Files \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) Microsoft Corporation。版权所有。

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

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

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

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

4

1 回答 1

3

Basically, it seems that the default DotNetCoreCLI@2 task will add --results-directory d:\a_temp parameter to the test command unless otherwise defined. This seems to prevent coverlet from running.

I changed the output filetype to cobertura for compatibility and added the following definition to the task: publishTestResults: false which seems to have solved my issue.

  - 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
于 2019-12-27T00:41:59.493 回答