首页 > 解决方案 > CTest 在简单的测试设置中找不到测试

问题描述

我正在向我的库中添加单元测试,但 ctest 总是说No tests were found!!!.

在我的最高级别CMakeLists.txt,我有以下内容

option(BUILD_TESTS OFF)

if (${BUILD_TESTS})
  enable_testing()
  add_subdirectory(tests)
endif()

和整数test/CMakeLists.txt

enable_testing()

project(test CXX)

add_executable(${PROJECT_NAME})

add_test(my_test ${PROJECT_NAME})

target_sources(
  ${PROJECT_NAME}
  PRIVATE
    test.cpp
)

test.cpp只是有一个简单的main()

bool test() {
  return true;
}

int main(int, char**) {
  return test() ? 0 : 1;
}

当我用cmake --build build/它构建时,甚至会CTestTestfile.cmake在构建目录中生成一个文件。但是当我现在跑步时,ctest -C Debug我得到了No tests were found!!!消息。

我怎样才能让这个基本测试起作用?

标签: c++cmakectest

解决方案


推荐阅读