Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(coding-guidelines): add note for test file with private headers #402

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Place source files and private header files.

### test directory

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