0

I have been trying to run tests using the vstest@2 task within azure devops pipelines and there are never any tests found when using the google test executable. I do have the test assembly specified to google test and Nuget restores google test in an earlier pipeline task.

Here is a snippet of my 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 is the google test executable that is generated using the vsbuild@1 task just before.

Below is the output from the vstest task.

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

I know I can use the command line task and run the google test executable and publish pipeline results from there, but I want to be able to use code coverage with the vstest task.

Edit for comments: When I run the following task just before the VSTest task I get output of all my tests.

- task: CmdLine@2
  inputs:
    script: '"<project repo output directory>/UnitTesting.exe" --gtest_list_tests'
  • Can you get the [code coverage](https://learn.microsoft.com/zh-cn/visualstudio/test/using-code-coverage-to-determine-how-much-code-is-being-tested?view=vs-2022&tabs=cpp#analyze-code-coverage-from-the-command-line) result on command line from your local machine? – Minxin Yu - MSFT Dec 20 '22 at 07:11
  • Please show `UnitTesting.exe --gtest_list_tests` output. – 273K Dec 20 '22 at 15:02
  • I am able to get a code coverage file using the command line on my local maching and doing UnitTesting.exe --gtest_list_tests gives me a huge list of tests, I have over 1000 tests in this project. ''' Req5Enabled01 Req5Enabled02 Req5Disabled01 Req5Disabled02 Req5Disabled03 Req5Enabled01 Req5Enabled02 ''' – whatisdevops Dec 20 '22 at 16:45
  • Try putting the exe ,GoogleTestAdapter files and dlls and in the same directory. Use absolute directory. – Minxin Yu - MSFT Dec 22 '22 at 08:36
  • @whatisdevops You could try to apply the solution proposed in https://stackoverflow.com/questions/73750442/vstest-console-exe-not-finding-google-tests-but-running-exe-with-gtest-list – sam Jul 22 '23 at 17:33

0 Answers0