0

I'am trying to create a build pipeline in Azure DevOps which contain a "vs test task". Nothing fancy here. I want to get the code coverage to send it to sonaQube. However, after the pipeline went through the task there is not .Coverage file created.

Error in vs test task

There is some errors that might be the issue but i'm not sure. there is a big "Data collection : Could not find data collector 'Code Coverage'", This might be related to the fact that my UnitTestProject.dll is built for Framework 4.6.2 and Platform AnyCPU(for this issue I tried to forced: otherConsoleOptions:/Framework:NETFramework,Version=v4.6.2').

My agent is running on Windows server 2012 and Visual Studio Enterprise everything is up to date: VS version

[command]"C:\Program Files (x86)\Microsoft VisualStudio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" @C:\Agent_AzureDevOps_1_work_temp\22f8bb11-e53e-11e9-95d5-5bdab8c29281.txt Microsoft (R) Test Execution Command Line Tool Version 15.9.0

My .trx file is created, however, my .coverage file is nowhere to be seen. I made sure Code Coverage was Enabled.

My package contain those NuGet NuGet in my package.config

I'am blocked and don't know where to look anymore if you guys have an idea.

Thanks for the time. If you guys want more information don't hesitate to ask.

  • The logs clearly say "Couldn't find data collector: Code Coverage". Did you do any troubleshooting on that? Is this a private agent or are you using the Microsoft hosted agents? If a private agent, did you verify that the appropriate Visual Studio SKU is installed to allow for code coverage collection? – Daniel Mann Oct 02 '19 at 19:16
  • Possible duplicate of [VSTests - Could not find diagnostic data adapter 'Code Coverage'](https://stackoverflow.com/questions/37834219/vstests-could-not-find-diagnostic-data-adapter-code-coverage) – Daniel Mann Oct 02 '19 at 19:20
  • It's a private agent hosted on a Windows Server 2012. – Sébastien Honorine Oct 02 '19 at 19:23
  • VSTests - Could not find diagnostic data adapter 'Code Coverage'. I ve check this post and no. its not a duplicate. – Sébastien Honorine Oct 02 '19 at 19:31
  • So your build server has VS Enterprise installed on it? – Daniel Mann Oct 02 '19 at 19:55
  • @SébastienHonorine, Please make sure you have only install the visual studio and the workloads you require, the build/test tools. If you have install the build tools, try to remove it. – Leo Liu Oct 03 '19 at 10:10
  • @DanielMann yes, as I posted [command]"C:\Program Files (x86)\Microsoft VisualStudio\2017\Enterprise\ leo Liu what do you mean ? from my pipeline or on the windows server directly? (sorry I'am not very good with all this stuff :/). – Sébastien Honorine Oct 03 '19 at 14:31

2 Answers2

0

I do not have enough reputation to add a comment, so I hope this post will not be deleted (although it is not a direct answer, I think). I wanted to suggest you the following:

Do you have an own *.runsettings file (where you might have specified a specific entry? If you do not specify a *.runsettings file by yourself, the Azure DevOps vstest@2 Task will use a "default" runsettings file. At least this is what I could observe in the log (debug=true)

Hope this helps

BR Michael

Michael
  • 11
  • 6
0

I have a similar problem. I run this command :

>dotnet test --logger trx "--collect:Code Coverage"
  Determining projects to restore...
  All projects are up-to-date for restore.
  MyAPI -> ...\MyApi\bin\Debug\net47\MyAPI.exe
  MyAPI.Tests -> ...\MyAPI.Tests\bin\Debug\net47\MyAPI.Tests.dll
Warning: Update the Microsoft.NET.Test.Sdk package reference to version 15.8.0 or later to collect code coverage.
Test run for ...\MyAPI.Tests\bin\Debug\net47\MyAPI.Tests.dll (.NETFramework,Version=v4.7)
Microsoft (R) Test Execution Command Line Tool Version 16.10.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Data collection : Unable to find a datacollector with friendly name 'Code Coverage'.
Data collection : Could not find data collector 'Code Coverage'
Results File: ...\MyAPI.Tests\TestResults\***_2021-09-03_12_02_21.trx

Passed!  - Failed:     0, Passed:    22, Skipped:     0, Total:    22, Duration: 201 ms - MyAPI.Tests.dll (net47)

The .trx is generated, but not the .coverage.

The solution is to add the NuGet package Microsoft.NET.Test.Sdk in the test project.

vernou
  • 6,818
  • 5
  • 30
  • 58