Search code examples
visual-studiocmakevisual-studio-2022googletest

VS2022 Test Explorer isn't showing tests written with GTest in a CMake project


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)

And HelloWorld.cpp

#include <gtest/gtest.h>

TEST(HelloWorld, Test)
{
    int i = 0;
    EXPECT_EQ(0, i);
}

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.


Solution

  • This actually turned out to be a visual studio configuration issue. There appears to be a conflict with CTest integration in Visual Studio and the Unreal Engine Test Adapter. Uninstalling the Unreal Engine Test Adapter has made everything work. I'll open an issue with the Visual Studio team.