![]() But I find this quite ugly and messy, to put component-specific stuff into the root file.Ĭonversely, I tried to move the include(CTest) command one level down into the component-specific CMakeLists.txt. However, if I call ctest, it returns No tests were found!!!Īfter playing a bit with this, it turned out that if I move the add_subdirectory(tests) call to the root CMakeLists.txt like this: if(BUILD_TESTING) ![]() The tests get successfully compiled and I can manually run them. In compX/tests/CMakeLists.txt I have the code to compile the test and the add_test()command. I want to enable ctest, therefore in the root CMakeLists.txt I have include(CTest) and in the component-specific CMakeLists.txt files I have if(BUILD_TESTING) I have a CMake-based project that consists of several sub-components, which can all be independently compiled and tested. $ source /opt/ros/groovy/setup.bash # OR ln -s /path/to/catkin. $ ln -s /path/to/catkin_demos/test_with_data. You can run them by making a workspace, and invoking catkin_make run_tests: $ mkdir test_ws I have setup a demo package that demonstrates both methods here: However, if you use an absolute path, the 2nd test method works as expected: catkin_add_gtest($2-test add) It looks like the WORKING_DIRECTORY argument is relative to the build directory. If I add a print of the current working directory to test_with_data2.cpp, it reports: ws/build/test_with_data/test. However, once the file is restored to the correct name, the second method still fails. Once that line is added, both tests fail with the mis-named test1.dat file. Adding the following line helps to catch this case: in.open("data/test.dat", std::fstream::in) ĪSSERT_FALSE(in.fail()) // this is the new lineĮXPECT_EQ(expected, test_with_data::add(op1, op2)) No tests are run if the file is not found, but neither is an error thrown. I think the issue is with how the test code loops over the data file lines. When I rename test.dat to test1.dat, both tests still pass. I tried running the example code provided by below. I'm leaving in this discussion for historical reasons, but the updated code should work as-is NOTE: William has updated his example code, so the following bugs have been fixed. Target_link_libraries(test_myPackage myPackage_lib) In case it's helpful, here's the relevant section of my CMakeLists.txt: catkin_add_gtest(test_myPackage test/utest.cpp) NOTE: I don't want the test executable or data-file to be installed in the final package. ![]() What is the best-practice for dealing with test data files under catkin? The build process does not copy my data file to this tree, so it is unclear how I should specify the relative path to my data file. ![]() In catkin, I run make run_tests and the working directory is in the catkin_ws/devel tree. So, I can reference the test data file using a relative path: test/test.dat. In rosbuild, I run tests using make test, and the working directory is the package root. This data file is in the same directory as my utest.cpp file: /test/test.dat. In one of the tests, I would like to read in an external data file to use in the test routine. I have set up my CMakeLists.txt to compile the unit-test program and link against my package library. This file will house a CMake helper function, addboosttest which will be used to generate a test runner usable by CTest from a single test source file. Next, create a text file called BoostTestHelpers.cmake. To begin, Boost.Test must be included in the project. I am creating a Unit-Test program for my catkin package, using gtest. This article assumes that a CMake based project already exists. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |