Skip to content

Commit

Permalink
docs(coding-guidelines): add note for test file with private headers (#…
Browse files Browse the repository at this point in the history
…402)

Signed-off-by: Takagi, Isamu <[email protected]>
  • Loading branch information
isamu-takagi authored Jun 20, 2023
1 parent 190caa0 commit 44a5a4c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docs/contributing/testing-guidelines/unit-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 44a5a4c

Please sign in to comment.