簡體   English   中英

Azure DevOps 2019 服務器無法執行具有代碼覆蓋率的測試

[英]Azure DevOps 2019 Server failed on executing tests with code coverage

現在的情況:

為了使我們的Azure DevOps 2019 服務器(代理)能夠構建ASP.NET Core 3.Net Core 3應用程序,我們在其上安裝了Build Tools for Visual Studio 2019 (expander Tools for Visual Studio 2019 )。 這不是最佳實踐,但 Azure DevOps 2019 服務器和代理安裝在同一台機器上。

除了收集編碼器覆蓋率外,一切都按預期進行。 構建了應用程序並提供了工件。 我們可以確認,發布后的所有工件都按預期工作。
就像已經提到的那樣,除了代碼覆蓋率之外,一切都很好。

要構建的應用程序是一個 .NET Framework 4.6.2 應用程序,並且是在 VS 2019 構建工具安裝之前構建的,在代理上成功使用 VS 2017 Enterprise。

Visual Studio build任務之后,我們在構建管道中使用 MSTest 和Visual Studio Test進行測試。 測試任務配置如下:

variables:
  SolutionRootDirectory: 'MySolutionRoot'
  SettingsFilePath: ''
  BuildPlatform: 'Any CPU'
  BuildConfiguration: 'Release'

steps:
- task: VSTest@2
  displayName: 'Test Assemblies: $(BuildConfiguration)'
  inputs:
    testAssemblyVer2: |
     **/*Test?(s).dll
     !**/obj/**
    searchFolder: '$(SolutionRootDirectory)'
    runSettingsFile: '$(SettingsFilePath)'
    codeCoverageEnabled: true
    testRunTitle: 'Test run: $(SolutionRootDirectory)\*.sln'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    diagnosticsEnabled: true
    collectDumpOn: always
    rerunFailedTests: false

所有測試都已成功執行,但任務失敗並顯示以下消息:

##[warning]Vstest failed with error. Check logs for failures. There might be failed tests.
##[error]Error: The process 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\Extensions\TestPlatform\vstest.console.exe' failed with exit code 1
Publishing test results to test run '11901'
Test results remaining: 260. Test run id: 11901
##[error]VsTest task failed.

檢查整個日志后,我發現以下消息:

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
   --- End of inner exception stack trace ---
   at Microsoft.VisualStudio.Diagnostics.Common.Check.Throw[XT](String message, Func`1 innerEx)
   at Microsoft.VisualStudio.Diagnostics.Logging.ProfilerInterop.ThrowInvariantExceptionOnZeroPtr(IntPtr ptr, String message)
   at Microsoft.VisualStudio.Diagnostics.Logging.ProfilerInterop.InitInterop()
   at Microsoft.VisualStudio.Diagnostics.Logging.ProfilerInterop..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.VisualStudio.Diagnostics.Logging.ProfilerInterop.get_InteropInterface()
   at Microsoft.VisualStudio.Diagnostics.Logging.LoggingConfig.Publish()
   at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.InitiateCollection()
   at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.GetEnvironmentVariables()
   at Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector.GetEnvironmentVariables()
   at Microsoft.VisualStudio.TestPlatform.Common.DataCollector.DataCollectorInformation.SetTestExecutionEnvironmentVariables()
   at Microsoft.VisualStudio.TestPlatform.Common.DataCollector.DataCollectionManager.GetEnvironmentVariables(Boolean& unloadedAnyCollector).

問題

有誰知道問題可能是什么?
我想,也許我們必須安裝Agents for Visual Studio 2019 (expander Tools for Visual Studio 2019 ),但我不確定這是否是正確的方法。 此外,我找不到任何有意義的信息,我們必須使用哪個安裝包 - AgentController

過去,大多數情況下,會完成完整的 Visual Studio Enterprise 安裝,以實現代理的完整功能集。 但我想要一種更干凈的方法,只想安裝需要的包,避免為構建代理使用企業許可證。

非常歡迎提出想法、方法和最佳實踐。 非常感謝您的幫助。

應用解決方案

好吧,在對最佳實踐進行大量研究和閱讀之后,最實用和最面向目標的解決方案是在build agent上安裝Visual Studio 2019 Enterprise 這是我的第一種方法,但提出了尋找另一個解決方案的問題,以避免在構建代理上安裝整個 VS 2019 Enterprise。

它包含所有需要的程序集,並且代碼覆蓋率僅是企業版的一部分。

我更喜歡該解決方案,因為不需要修改構建管道。 否則,必須修改所有現有的構建管道以匹配其他建議的解決方案。
如果可以接受編輯現有管道,以下列出了其他建議的解決方案。

所有建議的解決方案:

  1. 使用Coverlet ( Coverlet.MsBuild ) 通過 NuGet 將其安裝到測試項目中並導入其結果(可能與ReportGenerator結合使用
  2. 安裝Test Agent/Controller並在構建管道的 MSTest 任務中引用其vstest.console.exe
  3. 將所需的二進制文件復制到構建代理上的相關目錄

感謝您的建議和您投入的時間。

使用Visual Studio 測試平台安裝程序任務對我有用。

只要確保將vsTestVersion更改為toolsInstaller

- task: VisualStudioTestPlatformInstaller@1
  inputs:
    packageFeedSelector: 'nugetOrg'
    versionSelector: 'specificVersion'
    testPlatformVersion: '16.11.0'

- task: VSTest@2
  inputs:
    ...
    vsTestVersion: 'toolsInstaller'
    codeCoverageEnabled: true

(使用 16.11.0 版本測試,3 小時前發布,不確定之前是否可用)

對我來說有一個缺點,以前我可以使用一個變量/參數來設置 VSTest 和 VSBuild 版本,因為它們都有使用相同格式(15.0、16.0、最新)的版本參數,但工具安裝程序需要特定版本,所以它不是簡單明了如何保持同步,但也不清楚我們是否需要,也許不需要。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM