0

I am adding unit tests to my library but ctest always says No tests were found!!!.

In my top level CMakeLists.txt I have the following

option(BUILD_TESTS OFF)

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

and int 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
)

My test.cpp just has a simple main()

bool test() {
  return true;
}

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

When I build with cmake --build build/ it even generates a CTestTestfile.cmake file in the build directory. But when I now run ctest -C Debug I get the No tests were found!!! message.

How can I get this basic test to work?

Symlink
  • 383
  • 2
  • 12

0 Answers0