You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS2022 Test Explorer无法显示CMake项目中GTest编写的测试

VS2022中GTest CMake项目Test Explorer无法显示测试

昨天花了大半时间尝试在VS2022中运行基于GTest的CMake项目,项目可正常编译构建,但Test Explorer无法显示任何测试;点击「全部运行」后程序陷入无限循环无进展。已制作最小复现项目。

项目代码

CMakeLists.txt

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)

HelloWorld.cpp

#include <gtest/gtest.h>

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

通过「Test -> Run CTests」可正常运行测试,但Test Explorer毫无反应,输出窗口也未显示异常信息,目前毫无头绪。

内容的提问来源于stack exchange,提问作者Richard Watson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 08:43:15