【发布时间】:2020-05-31 17:08:15
【问题描述】:
我一直在查看 CMake 示例,以帮助我使用其测试文件夹构建我的项目。主要问题是我必须将我的测试文件夹中的所有 test/.cpp* 文件包含到 tests/main.cpp 中才能运行测试。我想我应该在我的 test/CMakeLists.txt 中使用 add_test 调用来包含我的测试。以下是我当前的 CMakeLists 文件:
enable_testing()
find_package(需要 GTest)
add_executable(test main.cpp)
target_include_directories(测试 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../include)
target_link_libraries(测试 MainProjectLib ${GTEST_LIBRARIES})
而我的 main.cpp 如下。
#include "file_in_test1.cpp"
#include "file_in_test2.cpp"
#include <gtest/gtest.h>
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
我阅读了一些使用标准 CTest 库进行单元测试的示例,但我使用的是 Google Test。 我希望能够运行 cmake、make 和 ./test 来运行 file_in_test1.cpp 和 file_in_test2.cpp 中的所有测试方法em> 无需直接将这些文件导入 test/main.cpp。 我必须对 CMakeLists.txt 进行哪些添加?
【问题讨论】:
标签: c++ cmake include googletest