在Azure DevOps中使用构建管道运行Google Test

时间:2019-09-30 10:58:19

标签: visual-studio-2017 azure-devops yaml googletest

我很难在自己的构建管道中运行我的gtest。我的解决方案很好地在Visual Studio 2017中构建和运行测试用例。在DevOps环境中,我使用.Net Desktop安装程序进行了少量修改。构建任务在管道中也可以正常工作。

我尝试使用默认的VSTest任务,但是我不确定使用VS IDE中的Visual Studio项目创建的运行Google Test的任务是否正确。

构建pipline 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\1\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\**.

1 个答案:

答案 0 :(得分:1)

是的,VSTest任务将使用VSTest.Console.exe。它能够运行自定义测试适配器(例如Google测试适配器)。

但是,在经过Hosted VS2017构建代理的内置随附软件后,未列出。如果是这样,您可以使用Self-hosted Windows agents

您可以将Google测试适配器下载为Visual Studio扩展,将其解压缩(将.vsix文件重命名为.zip),然后将整个解压缩的文件夹放在Build Agent计算机上的某个位置。然后,构建步骤必须指向该目录。

enter image description here

当然,您的项目还应包括“ googletest” NuGet程序包以运行测试。

如果仍然无法正常工作,请远程构建代理计算机,并使用Visual Studio或命令行(而不是通过Azure DevOps管道)手动运行构建和测试。如果这是环境问题,它将缩小范围。