首页 > 解决方案 > 数据收集器“代码覆盖率”未能提供初始化信息

问题描述

我正在尝试使用构建管道创建代码覆盖率报告。Visual Studio code我在构建管道中添加了类型任务并启用了代码覆盖率。

触发构建时。我越来越 :

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.

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

这正在运行测试并且所有测试都通过了。但是我无法查看代码覆盖率报告。它创建的报告仅包含有关测试的信息

我们指定路径的任何输入都会很有用。

标签: unit-testingbuildcode-coverageazure-pipelines

解决方案


您基本上需要用于代码覆盖率的Visual Studio 测试代理。

有两种可能的安装方法:

  • 选项1
    1. 在构建服务器上安装Agents for Visual Studio 2019(从此处下载,请参阅Visual Studio 2019 的工具)。
    2. 在构建管道中编辑Visual Studio Test Assemblies任务。设置Select test platform using为,例如Specific location设置为。Path to vstest.console.exeC:\Program Files (x86)\Microsoft Visual Studio\2019\TestAgent\Common7\IDE\Extensions\TestPlatform\vstest.console.exe
  • 选项 2
    1. Visual Studio test platform installer构建任务添加到您的管道。(在测试任务之前添加此任务)。
    2. 在任务中,Visual Studio Test Assemblies您必须选择Installed by Tools InstallerTest platform version

注意:根据我的经验,我有一些测试在选项 1 中成功,但在选项 2 中失败。可惜我没有时间弄清楚为什么...


推荐阅读