【发布时间】:2021-08-04 19:10:55
【问题描述】:
我正在使用 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)
【问题讨论】:
-
你先运行 CMake 了吗?
-
是的,我做了
cmake -G"MSYS Makefiles" ..然后cmake --build build -
我的 CMakeLists 文件有什么问题,我拥有的文件是 fact.cpp、main.cpp、testt.cpp、header.h
标签: c++ cmake googletest