You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps中VSTest@2调用Google Test可执行文件无法发现测试

问题:Azure DevOps VSTest@2任务启用代码覆盖率时无法发现Google Test测试

问题背景

在Azure DevOps流水线中使用VSTest@2任务运行Google Test可执行文件,始终无法发现测试。已通过NuGet还原Google Test依赖,且测试程序集路径配置正确,核心需求是通过VSTest任务实现代码覆盖率统计。

流水线YAML配置片段

- task : VSBuild@1
  displayName: 'VSbuild'
  inputs :
    solution : '$(solution)'
    platform : '$(buildPlatform)'
    configuration : ${{parameters.buildconfiguration}}


- task: VSTest@2
  inputs:
    searchFolder:  '$(System.DefaultWorkingDirectory)/<ProjectRepo>'
    resultsFolder: '$(System.DefaultWorkingDirectory)/TestResults'
    testAssemblyVer2: |
      **\UnitTesting.exe
    codeCoverageEnabled: true
    pathtoCustomTestAdapters: '$(System.DefaultWorkingDirectory)/GoogleTestAdapter'
    platform: '$(buildPlatform)'
    configuration: ${{parameters.buildconfiguration}}

注:UnitTesting.exe是VSBuild@1任务生成的Google Test可执行文件

VSTest任务日志输出

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe "@D:\a\_temp\c4zmbclzr0a.tmp"
Microsoft (R) Test Execution Command Line Tool Version 16.11.0
Copyright (c) Microsoft Corporation.  All rights reserved.
vstest.console.exe "D:\a\1\s\<project repo>\UnitTesting.exe"
/Settings:"D:\a\_temp\2kvnbwgfz0c.tmp.runsettings"
/EnableCodeCoverage
/Logger:"trx"
/TestAdapterPath:"D:\a\1\s\<project repo>\GoogleTestAdapter"
Starting test execution, please wait...
2.391
A total of 1 test files matched the specified pattern.
No settings file provided through env variable GTA_FALLBACK_SETTINGS
Warning: Using default settings.
Google Test Adapter: Test execution starting...
Found 0 tests in executable D:\a\1\s\<project repo>\UnitTesting.exe
##[error]Test discovery was cancelled after 30s for executable 'D:\a\1\s\<project repo>\UnitTesting.exe'
Google Test execution completed, overall duration: 00:00:31.6375081.
##[error]================
##[error]The following warnings and errors occured during test execution (enable debug mode for more information):
##[error]Test discovery was cancelled after 30s for executable 'D:\a\1\s\<project repo>\UnitTesting.exe'
No test is available in D:\a\1\s\<project repo>\UnitTesting.exe. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
Results File: D:\a\1\s\TestResults\VssAdministrator_WIN-CVJL4F2UTMJ_2022-12-19_22_25_03.trx
Attachments:
  D:\a\1\s\TestResults\e27d838c-1572-409c-886c-741d2b1a6e51\VssAdministrator_WIN-CVJL4F2UTMJ_2022-12-19.22_24_28.coverage
##[error]Test Run Failed.
vstest.console.exe exited with code 1.
**************** Completed test execution *********************
Test results files: D:\a\1\s\TestResults\VssAdministrator_WIN-CVJL4F2UTMJ_2022-12-19_22_25_03.trx
No Result Found to Publish 'D:\a\1\s\TestResults\VssAdministrator_WIN-CVJL4F2UTMJ_2022-12-19_22_25_03.trx'.
Created test run: 1381422
Publishing test results: 0
Publishing test results to test run '1381422'.
TestResults To Publish 0, Test run id:1381422
Published test results: 0
Publishing Attachments: 2
Execution Result Code 1 is non zero, checking for failed results
Completed TestExecution Model...
##[warning]Vstest failed with error. Check logs for failures. There might be failed tests.
##[error]Error: The process 'D:\a\_tasks\VSTest_ef087383-ee5e-42c7-9a53-ab56c98420f9\2.210.0\Modules\DTAExecutionHost.exe' failed with exit code 1
##[error]Vstest failed with error. Check logs for failures. There might be failed tests.
Finishing: VSTest

补充验证

通过CmdLine任务直接调用测试可执行文件,能够正常列出所有测试用例:

- task: CmdLine@2
  inputs:
    script: '"<project repo output directory>/UnitTesting.exe" --gtest_list_tests'

问题原因及结论

该问题是Google Test Adapter的固有限制导致:其官方文档明确说明,使用VsTest.Console运行时调试能力未定义,而VSTest@2任务本质是VsTest.Console的前端封装,因此无法同时启用调试和代码覆盖率收集功能。

内容的提问来源于stack exchange,提问作者whatisdevops

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 15:25:10