diff --git a/docs/contributing/coding-guidelines/ros-nodes/directory-structure.md b/docs/contributing/coding-guidelines/ros-nodes/directory-structure.md index 386cf939bca..3e4de9866a0 100644 --- a/docs/contributing/coding-guidelines/ros-nodes/directory-structure.md +++ b/docs/contributing/coding-guidelines/ros-nodes/directory-structure.md @@ -68,7 +68,7 @@ Place source files and private header files. #### `test` -Place source files for testing. +Place source files for testing. See [unit testing](../../testing-guidelines/unit-testing.md) for details. ## Python package diff --git a/docs/contributing/testing-guidelines/unit-testing.md b/docs/contributing/testing-guidelines/unit-testing.md index 7adc7d9cad5..61c650ac5d4 100644 --- a/docs/contributing/testing-guidelines/unit-testing.md +++ b/docs/contributing/testing-guidelines/unit-testing.md @@ -41,12 +41,14 @@ if(BUILD_TESTING) ament_add_ros_isolated_gtest(test_my_cool_pkg test/test_my_cool_pkg.cpp) target_link_libraries(test_my_cool_pkg ${PROJECT_NAME}) + target_include_directories(test_my_cool_pkg PRIVATE src) # For private headers. ... endif() ``` This automatically links the test with the default main function provided by `gtest`. The code under test is usually in a different CMake target (`${PROJECT_NAME}` in the example) and its shared object for linking needs to be added. +If the test source files include private headers from the `src` directory, the directory needs to be added to the include path using `target_include_directories()` function. To register a new `gtest` item, wrap the test code with the macro `TEST ()`. `TEST ()` is a predefined macro that helps generate the final test code,