Collecting code coverage with dotnet test on azure devops yaml pipeline

Viewed 2737

I've tried all I can find to figure this out.

I have several fresh .net core 3.1 or .net standard 2 projects that are building on Azure DevOps Services. I'm trying to setup the code coverage for these projects and I'm getting nowhere.

When running a test locally I get a success and the code coverage result is created.

3/24/20 3:39 [jgust] [portChangesFromAggregateRepo ≡]
>: dotnet test .\Common.UnitTests\ --collect:"Code coverage"
Test run for C:\src\bio\lib\Common\src\Common.UnitTests\bin\Debug\netcoreapp2.2\Common.UnitTests.dll(.NETCoreApp,Version=v2.2)
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.

Attachments:
  C:\src\bio\lib\Common\src\Common.UnitTests\TestResults\74f826e4-4a46-46dd-9fe5-7fd17b8cee1c\2020-03-24.15_40_28.coverage
Test Run Successful.
Total tests: 794
     Passed: 794
 Total time: 19.3390 Seconds

However, when running this project on Azure DevOps, the build reports that the collector can't be found.

A total of 1 test files matched the specified pattern.
Data collection : Could not find data collector 'Code coverage'
Results File: d:\a\_temp\VssAdministrator_fv-az130_2020-03-24_20_53_07.trx

Test Run Successful.
Total tests: 794
     Passed: 794

The pipeline task for this is as follows:

enter image description here

and yes I'm using windows platform here

enter image description here

What am I missing about setting up code coverage collection for these projects.

As far as I can tell, I'm going everything strait out of the book

Also, I am using the described version of package:

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />

1 Answers

You should specify the path to the csproj file(s) of your test project in Path to project(s), and make sure the test project reference Microsoft.NET.Test.SDK version 15.8.0 or higher

While specifying paths to the .dll files will enable the dotnet test command under the task to run the tests, it will not allow the collection of coverage data. That operation requires paths to .csproj files.

Try using $(System.DefaultWorkingDirectory)\**\*${{ parameters.slnName }}*[T|t]est*.csproj

Note: this specification should make the negations obsolete.

Related