CTest

假设现在有一个路径如下

.
├── CMakeLists.txt
├── src
│   └── CMakeLists.txt
└── test
    ├── CMakeLists.txt
    └── main.cpp

则使用 CTest 的方式为:

  1. 在 CMakeLists.txt 中引入 CTest

    include(CTest)
    
  2. 在 test/CMakeLists 中写入:

    add_executable(someTest main.cpp)
    add_test(TestLayout someTest)
    

之后使用的方式为:

cmake --build build
cd build && ctest