Creating a test report with Azure Pipelines and Coverlet does not create the coverage.opencover.xml file

Here is my solution structure:

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

The build script works otherwise fine, but I'm unable to get it to create the coverlet results as coverage.opencover.xml format at the root folder.

My 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

As a result, I get the following output for the Testing **/*.UnitTests/*.csproj task:

Starting: Testing **/.UnitTests/.csproj ============================================================================== Task:.NET Core Description: Build, test, package, or publish a dotnet application, or run a custom dotnet command Version
: 2.162.0 Author: Microsoft Corporation Help: https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli ============================================================================== C:\windows\system32\chcp.com 65001 Active code page: 65001 "C:\Program Files\dotnet\dotnet.exe" test 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] Test run for d:\a\1\s\BlazorApp.UnitTests\bin\Release\netcoreapp3.1\BlazorApp.UnitTests.dll(.NETCoreApp,Version=v3.1) Microsoft (R) Test Execution Command Line Tool Version 16.3.0 Copyright (c) Microsoft Corporation. All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern. Results File: d:\a_temp\VssAdministrator_fv-az74_2019-12-25_11_32_03.trx

Test Run Successful. Total tests: 1 Passed: 1 Total time: 1.5842 Seconds

Problem is that no coverage.opencover.xml file is created even the yml parameters define the coverlet settings which should be executed. The codecov.ps1 PowerShell script works if it can find the test result file which is now missing.

2 ответа

В принципе кажется, что по умолчанию 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

Вы также можете убедиться, что ваш проект модульного тестирования содержит ссылки NuGet для coverlet.msbuild и OpenCover. Я думаю, что один coverlet.msbuild должен быть в порядке.

Другие вопросы по тегам