使用 ShimContext.Create() 的单元测试在 Azure DevOps 管道上出错

Unit Tests that use ShimContext.Create() getting error on Azure DevOps Pipeline

我有一些使用 Fakes 和 ShimContext 的单元测试。 当他们 Visual Studio Enterprise 2017 运行 IDE 他们 运行 成功时,但是,当单元测试 运行 在管道上时,他们抛出以下错误:

错误信息:

测试方法 MyTestMehodName 抛出异常: Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationException:分析器库中的 SetDetourProvider 返回意外错误 'C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\Common7\IDE\CommonExtensions\Microsoft\IntelliTrace\Microsoft.IntelliTrace.Profiler.dll'。

堆栈跟踪:

在Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.IntelliTraceInstrumentationProvider.Initialize() 在 Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InitializeUnitTestIsolationInstrumentationProvider() 在 Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.CreateContext() 在 Microsoft.QualityTools.Testing.Fakes.ShimsContext.Create() 在 \ProjectTestName\TestFileName.cs: 第 115 行

中的 MySolutuionPath.MyTestMehodName()

当我将新的 TestSetting 文件添加到解决方案并启用 IntelliTrace 选项时,我能够在 Visual Studio IDE 上重现此错误: Adding Test setting file to solution

构建服务器的配置:

这是我的测试方法

[TestMethod]
public void MyTestMethodName()
{
      using (ShimsContext.Create())
      {
          // Unit Test goes here with Assert
      }
}

这是管道的样子: Pipeline 这是 YAML 配置

steps:
 - task: VSTest@2
  displayName: 'Run Unit Tests'
  inputs:
    testAssemblyVer2: |
     **\*test*.dll
     !**\*TestAdapter.dll
     !**\obj\**
     !**\*QualityTools.UnitTestFramework.dll
     !**\*QualityTools.Testing.Fakes.dll
    searchFolder: '$(Build.BinariesDirectory)'
    vsTestVersion: toolsInstaller
    runInParallel: true
    runTestsInIsolation: false
    codeCoverageEnabled: false
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
  continueOnError: true

我尝试过的解决方案:

我想知道我是否遗漏了构建服务器上的任何安装。但是,如果单元测试 运行 在 IDE(测试资源管理器)中成功,我认为我缺少任何东西。

根据 this stack overflow post,您可以尝试将构建代理服务更改为以普通特权用户身份登录,而不是 system/local 用户。