-
Notifications
You must be signed in to change notification settings - Fork 8
Add AI ssistants guide to follow ROS 2 project testing best practices from the workshop #52
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7d42358
add instructions to use professional testing best practices when usin…
xaru8145 b25b13d
add testing guide for AI assistants
xaru8145 9720629
update README to link properly the AI testing guide
xaru8145 8a176a2
update guide
xaru8145 c32ae77
fix readme prompt for AI assistants
xaru8145 e291a17
address reviewer's comments
xaru8145 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # AI ROS 2 Testing Guide | ||
|
|
||
| This document defines professional engineering and testing standards for ROS 2 software development. AI assistants generating ROS 2 code or tests must strictly adhere to these rules to ensure safety, maintainability, and reliability in production-ready systems. | ||
|
|
||
| ## Testable Design | ||
|
|
||
| To enable professional-grade testing, algorithmic logic must be decoupled from the ROS 2 middleware. | ||
|
|
||
| Follow these relevant SOLID principles: | ||
|
|
||
| - **Single Responsibility (SRP)**: Build ROS 2 nodes to have a single responsibility. Separate application logic into its own class or library, and keep ROS 2 nodes as thin wrappers responsible only for communication between ROS interfaces and the core application logic. | ||
|
|
||
| - **Dependency Injection (DI)**: Inject dependencies and configurations into the logic class constructor rather than creating them internally. This enables the use of mocks to isolate functionality during testing. | ||
|
|
||
| - **Interface Segregation (ISP)**: Depend on abstractions, not concrete implementations, to allow for seamless substitution of real components with fakes or mocks in unit tests. | ||
|
|
||
| ## Testing Strategy | ||
|
|
||
| Maintain a balanced testing pyramid to ensure high-quality software: | ||
|
|
||
| - **Static Analysis (Foundation)**: Use linters and formatters to catch style, naming, and memory issues before runtime. | ||
|
|
||
| - **Unit Tests (Majority)**: Target the ROS-independent logic class using GoogleTest (`gtest`) and the **Arrange-Act-Assert (AAA)** pattern. Aim for 90-100% coverage on core algorithms. These must be ROS-agnostic, fast, and deterministic. | ||
|
|
||
| - **ROS Unit/Component Tests**: Validate node interfaces (topics, services, parameters) in isolation using test fixtures to manage the `rclcpp` lifecycle. | ||
|
|
||
| - **Integration Tests**: Verify multi-node interactions and communication behavior using the `launch_testing` framework. | ||
|
|
||
| - **End-to-End (E2E)**: Validate complete system behavior in realistic environments, such as simulation or on target hardware. | ||
|
|
||
| ## Determinism and Reliability | ||
|
|
||
| - **Avoid Arbitrary Sleeps**: Never use arbitrary sleeps in tests, as they make them non-deterministic and flaky. | ||
|
|
||
| - **Synchronization Mechanisms**: Instead of sleeping, use synchronization mechanisms or wait for the expected result with a proper timeout. | ||
|
|
||
| - **Test Isolation**: Always use `ament_add_ros_isolated_gtest` to prevent cross-talk between parallel tests on the same network by assigning unique domain IDs. | ||
|
|
||
| ## Local Development | ||
|
|
||
| - **Pre-commit Hooks**: Use pre-commit hooks to automatically run formatting, linters, and other fast checks before committing code. This helps catch issues early and reduces CI failures. | ||
|
|
||
| ## Continuous Integration | ||
|
|
||
| The CI pipeline (e.g., **GitHub Action**s) serves as an enforceable quality gate. | ||
|
|
||
| 1. **Build**: Run colcon build to ensure the package and its dependencies compile correctly. | ||
|
|
||
| 2. **Test and Lint**: Execute colcon test. This triggers both the Static Analysis and the functional tests (Unit, ROS Unit, Integration). | ||
|
|
||
| 3. **Verification**: Use `colcon test-result --verbose` to interpret results. | ||
|
|
||
| 4. **Enforcement**: Configure branch protection rules to require these status checks pass before code can be merged. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.