运行 Google 在 Azure DevOps 中使用构建管道进行测试
Run Google Test with build pipeline in Azure DevOps
我在构建管道中获取 gtest 运行ing 时遇到问题。我的解决方案适用于在 Visual Studio 2017 年构建和 运行 测试用例。在 DevOps 环境中,我使用 .Net 桌面设置并稍作修改。构建任务在管道中也能正常工作。
我尝试使用默认的 VSTest 任务,但我不确定 运行 Google 使用来自 VS Visual Studio 项目创建的测试的正确任务 IDE .
构建管道 yml 脚本
# .NET Desktop
trigger:
- master
# Install build environment
pool:
vmImage: 'windows-latest'
name: Hosted VS2017
variables:
solution: '**/*.sln'
buildPlatform: 'x86'
buildConfiguration: 'Debug'
steps:
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
# Build VS solutions including gtest project.
- task: VSBuild@1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
# Run gTest, this task not working see log below.
- task: VSTest@2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
VSTest 日志输出
Running tests using vstest.console.exe runner.
======================================================
Test selector : Test assemblies
Test filter criteria : null
Search folder : d:\a\s
VisualStudio version selected for test execution : latest
Attempting to find vstest.console from a visual studio installation with version [16.0,17.0).
Attempting to find vstest.console from a visual studio build tools installation with version [16.0,17.0).
Attempting to find vstest.console from a visual studio installation with version [15.0,16.0).
Run in parallel : false
Run in isolation : false
Path to custom adapters : null
Other console options : null
Code coverage enabled : false
Diagnostics enabled : false
SystemVssConnection exists true
Run the tests locally using vstest.console.exe
========================================================
##[warning]No test assemblies found matching the pattern: **\*test*.dll,!**\*TestAdapter.dll,!**\obj\**.
是的,将使用 VSTest.Console.exe
的 VSTest 任务。它能够 运行 自定义测试适配器(如 Google 测试适配器)。
但是,通过Hosted VS2017 build agent 的内置Included Software 后,它没有列出。如果是这样,您可以使用 Self-hosted Windows agents.
您可以下载 Google 测试适配器作为 Visual Studio 扩展,将其解压缩(将 .vsix 文件重命名为 .zip)并将整个解压缩的文件夹放在您的构建代理机器上的某个位置。然后构建步骤必须指向该目录。
当然,您的项目还应该包含 "googletest" NuGet 包,以便 运行 进行测试。
如果您仍然无法让它工作,请远程构建代理机器并手动 运行 构建和测试使用 visual studio 或命令行而不是通过 Azure DevOps 管道。如果是环境问题,这将缩小范围。
我在构建管道中获取 gtest 运行ing 时遇到问题。我的解决方案适用于在 Visual Studio 2017 年构建和 运行 测试用例。在 DevOps 环境中,我使用 .Net 桌面设置并稍作修改。构建任务在管道中也能正常工作。
我尝试使用默认的 VSTest 任务,但我不确定 运行 Google 使用来自 VS Visual Studio 项目创建的测试的正确任务 IDE .
构建管道 yml 脚本
# .NET Desktop
trigger:
- master
# Install build environment
pool:
vmImage: 'windows-latest'
name: Hosted VS2017
variables:
solution: '**/*.sln'
buildPlatform: 'x86'
buildConfiguration: 'Debug'
steps:
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
# Build VS solutions including gtest project.
- task: VSBuild@1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
# Run gTest, this task not working see log below.
- task: VSTest@2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
VSTest 日志输出
Running tests using vstest.console.exe runner.
======================================================
Test selector : Test assemblies
Test filter criteria : null
Search folder : d:\a\s
VisualStudio version selected for test execution : latest
Attempting to find vstest.console from a visual studio installation with version [16.0,17.0).
Attempting to find vstest.console from a visual studio build tools installation with version [16.0,17.0).
Attempting to find vstest.console from a visual studio installation with version [15.0,16.0).
Run in parallel : false
Run in isolation : false
Path to custom adapters : null
Other console options : null
Code coverage enabled : false
Diagnostics enabled : false
SystemVssConnection exists true
Run the tests locally using vstest.console.exe
========================================================
##[warning]No test assemblies found matching the pattern: **\*test*.dll,!**\*TestAdapter.dll,!**\obj\**.
是的,将使用 VSTest.Console.exe
的 VSTest 任务。它能够 运行 自定义测试适配器(如 Google 测试适配器)。
但是,通过Hosted VS2017 build agent 的内置Included Software 后,它没有列出。如果是这样,您可以使用 Self-hosted Windows agents.
您可以下载 Google 测试适配器作为 Visual Studio 扩展,将其解压缩(将 .vsix 文件重命名为 .zip)并将整个解压缩的文件夹放在您的构建代理机器上的某个位置。然后构建步骤必须指向该目录。
当然,您的项目还应该包含 "googletest" NuGet 包,以便 运行 进行测试。
如果您仍然无法让它工作,请远程构建代理机器并手动 运行 构建和测试使用 visual studio 或命令行而不是通过 Azure DevOps 管道。如果是环境问题,这将缩小范围。