I spent most of the day yesterday trying to get a GTest CMake project to work in VS2022. Everything builds and compiles but test explorer won’t show any tests. Hitting Run All causes it to sit in an infinite loop not progressing. I’ve produced a minimal repro here https://github.com/GingerbreadFred/GoogleTestRepro/.
The CMakeLists for the project is below
cmake_minimum_required(VERSION 3.5)
project(HelloWorldTest)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/f8d7d77c06936315286eb55f8de22cd23c188571.zip
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()
add_executable(HelloWorld
src/HelloWorld.cpp
)
target_link_libraries(HelloWorld GTest::gtest_main)
include(GoogleTest)
gtest_discover_tests(HelloWorld)
The tests work if I do Test -> Run CTests but test explorer is oblivious. I can’t see anything in the output window that would suggest what the problem is. To be honest I’m stumped
Richard Watson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1