假设现在有一个路径如下 :
.
├── CMakeLists.txt
├── src
│ └── CMakeLists.txt
└── test
├── CMakeLists.txt
└── main.cpp则使用 CTest 的方式为:
在 CMakeLists.txt 中启用测试功能
include(CTest) enable_testing()在 test/CMakeLists 中写入:
add_executable(someTest main.cpp) add_test(TestLayout someTest)
之后使用的方式为:
cmake --build build
cd build && ctest