我正在使用 gtest 来测试我的 C++ 项目。我按照 here
中的步骤操作一切顺利,但是当我运行 cd build && ctest
命令时,我得到的输出为 Test project C:/Users/admin/Desktop/last/build No tests were found!!!
我的 CMakeLists.txt 文件
cmake_minimum_required(VERSION 3.14)
project(last)
# GoogleTest requires at least C++11
set(CMAKE_CXX_STANDARD 11)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()
add_executable(
hello_test
fact.cpp
header.h
main.cpp
testt.cpp
)
target_link_libraries(
hello_test
gtest_main
)
include(GoogleTest)
gtest_discover_tests(hello_test)
答案 0 :(得分:0)
我更改了 CMakeLists 文件中的一行
add_executable(
hello_test
header.h
main.cpp
)
并添加了一行
add_test(testt.cpp hello_test)
这给了我正确的输出并运行了测试