3

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://learn.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.

ajr
  • 874
  • 2
  • 13
  • 29

2 Answers2

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
ajr
  • 874
  • 2
  • 13
  • 29
  • 1
    I'm using coverlet in similar way but had the same problem when I changed to a windows VM (from unbuntu). My coverage report in Azure Devops disappeared simply cos I changed VM type. I set `nobuild: true` and `publishTestResults: false` and it came back. Thanks for this answer! – bytedev Jun 25 '20 at 10:18
1

You can also ensure that your unit test project contains NuGet references for coverlet.msbuild and OpenCover. I think coverlet.msbuild alone should be fine.

Juan.M
  • 21
  • 4