This should be a fairly simple question, but given the black arts of project structuring using cmake, it will help quite a bit of people struggling with this.
I'm trying to get my codebase a little bit more organized. For this, I'm creating subfolders that contain the test suites according to their domain.
Google test itself is already compiling and running, the only thing is that with this restructure, Google Test can't find any of the Test Cases I have.
Here is my structure:
tests\
|
\domain1\
|CMakeLists.txt
|domain1_test.cpp
|domain1_test.hpp
|[.. more tests ...]
\domain2\
|CMakeLists.txt
|domain2_test.cpp
|domain2_test.hpp
|[.. more tests ...]
|main.cpp
|CMakeLists.txt
As you can see, I have two folders where tests live.
The CMakeLists.txt files in those are as follows:
SET(DOMAIN1_TEST_SRC
domain1_test.cpp
domain1_test.hpp)
ADD_LIBRARY(domain1testlib STATIC ${DOMAIN1_TEST_SRC})
TARGET_LINK_LIBRARIES(domain1testlib
${Boost_LIBRARIES}
domain_lib
gtest
)
TARGET_INCLUDE_DIRECTORIES(domain1testlib
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR})
The CMakeLists.txt in the main tests directory is:
add_subdirectory(domain1)
add_subdirectory(domain2)
ADD_EXECUTABLE(my_domain_tests main.cpp)
TARGET_LINK_LIBRARIES(my_domain_tests
${Boost_LIBRARIES}
domain1testlib
domain2testlib
comptestlib
gtest
)
add_test(MyTestSuite my_domain_tests)
What am I doing wrong?
Running tests just says that No tests were found.
Thanks!
UPDATE Adding my main.cpp
It's really nothing special, just the boilerplate main.cpp file.
#include "gtest/gtest.h"
int main(int argc, char ** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
main.cpp? Do you need it or can you link againstgtest_maininstead ofgtest, allowing gtest itself to work out what tests are available to run? Does your top levelCMakeLists.txthaveenable_testing()called somewhere? - Craig Scottmain.cppfile I'm using.Yes, my top level CMakeLists.txt has theenable_testing()call. - Hector Villarreal