Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data collector 'Code Coverage' failed to provide initialization information

I'm trying to create a code coverage report using the Build pipeline. I have added the task of typeVisual Studio code in the build pipeline and have enabled the Code Coverage.

When the build is triggered. I'm getting :

Data collector 'Code Coverage' message: Data collector 'Code Coverage' failed to provide initialization information. Error: System.TypeInitializationException: The type initializer for 'Microsoft.VisualStudio.Diagnostics.Logging.ProfilerInterop' threw an exception. ---> Microsoft.VisualStudio.Diagnostics.Common.InvariantException: Failed to load IntelliTrace Profiler binary or failed to locate functions.

and

---> System.ComponentModel.Win32Exception: The system cannot find the path specified

This is running the tests and all the tests are passed. However I'm not able to view the code coverage report. The report which it has created contains only information about the tests

Any input on where we specify the path will be useful.

like image 659
Dev Avatar asked May 09 '19 21:05

Dev


2 Answers

You basically need Visual Studio Test Agent for Code Coverage.

There are 2 possible ways to install for this:

  • Option 1
    1. Install Agents for Visual Studio 2019 on the Build server (download from here, see under Tools for Visual Studio 2019).
    2. In the build pipeline edit the Visual Studio Test Assemblies task. Set Select test platform using to Specific location and set Path to vstest.console.exe to for example C:\Program Files (x86)\Microsoft Visual Studio\2019\TestAgent\Common7\IDE\Extensions\TestPlatform\vstest.console.exe.
  • Option 2
    1. Add the Visual Studio test platform installer build task to your pipeline. (Add this task before the testing task).
    2. In the Visual Studio Test Assemblies task you have to select Installed by Tools Installer as the Test platform version

Note: in my experience I had some tests who succeeded with option 1, but failed in option2. Sadly I don't have the time to figure out why...

like image 155
Floris Devreese Avatar answered Oct 01 '22 01:10

Floris Devreese


I faced this issue when configuring a build container.

1 To install the Visual Studio 2019 Test Agent, I used Chocolatey

1.2 Install Chocolatey

ENV chocolateyUseWindowsCompression = false

SHELL ["powershell.exe", "-ExecutionPolicy", "Bypass", "-Command"]
RUN Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')); `
    [System.Environment]::SetEnvironmentVariable('PATH', "\"${env:PATH};%ALLUSERSPROFILE%\chocolatey\bin\"", 'Machine'); `
    choco feature enable -n allowGlobalConfirmation;

1.2 Install the TestAgent with chocolatey

RUN choco install visualstudio2019testagent -y

2. Edit the VSTest task on your pipeline to use a specific location.

In my case, I've installed into the container the VSBuildTools. The VSTest task used the VSBuildTools vstest.console.exe but the execution needs some libraries that are located at the TestAgent folders.

vstestLocationMethod: location
vstestLocation: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\TestAgent\Common7\IDE\Extensions\TestPlatform\vstest.console.exe'
like image 32
Thalles Noce Avatar answered Oct 03 '22 01:10

Thalles Noce