ROS2 Testing

Implements unit, integration, and E2E test strategies for ROS2 applications in Python and C++.

Updated Aug 16, 2026
One-click install
npx skills add https://github.com/three1324/yeonjinautomotive --skill ros2-testing-three1324
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ROS2 Testing
Source: https://github.com/three1324/yeonjinautomotive/tree/main/.claude/skills/ros2_testing
Command: npx skills add https://github.com/three1324/yeonjinautomotive --skill ros2-testing-three1324

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Testing ROS2 robotics applications is difficult because nodes depend on the ROS runtime, making it hard to isolate business logic and verify behavior across the full stack. This Skill provides a structured test pyramid and concrete patterns for testing ROS2 code that follows Clean Architecture. ## Core Features & Use Cases - Layered Test Pyramid: Organizes tests into unit (domain/application logic), integration (node/component), and E2E (launch tests) tiers with a clear directory structure. - Python Testing with pytest: Provides fixtures for managing rclpy init/shutdown lifecycle and patterns for node-level integration tests using publishers and subscribers. - C++ Testing with GTest/GMock: Demonstrates mocking repository interfaces for domain use cases and spinning up real nodes for component tests. - Launch-Based System Tests: Shows how to run GTest executables inside launch files with launch_testing for full system verification. - Use Case: When building a robot control package, use this Skill to write pure unit tests for your controller logic with mocked repositories, then add node integration tests and a launch test that boots the real system. ## Quick Start Ask the AI to generate a pytest integration test for a ROS2 sensor node following the Clean Architecture test pyramid.

Frequently Asked Questions about ROS2 Testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write unit tests for ROS2 nodes in Python?

Keep domain logic free of ROS dependencies so it can be tested as pure Python with pytest. For node-level tests, use pytest fixtures that call rclpy.init and rclpy.shutdown, then create helper nodes to publish and subscribe to topics.

How to mock dependencies in ROS2 C++ tests with GTest?

Define interfaces for repositories or services in the domain layer, then create mock classes with gmock MOCK_METHOD macros. Inject the mock into your use case and set expectations with EXPECT_CALL and WillOnce(Return(...)).

What is the difference between ROS2 integration tests and launch tests?

Integration tests instantiate individual nodes or components and verify their topic behavior in isolation. Launch tests use launch_testing to start the full system and run assertions or GTest executables against the running application.

Can I run GTest executables from a ROS2 launch file?

Yes, add the GTest executable as a Node action in the launch description alongside the system under test, and include ReadyToTest from launch_testing.actions. This enables system-level verification within a standard launch test.

Why should ROS2 domain logic be separated from node code for testing?

Separating domain logic from rclpy or rclcpp dependencies lets unit tests run without initializing a ROS context, making them fast and deterministic. ROS-dependent code is then covered separately by integration and launch tests.

How do I handle async operations in ROS2 C++ tests?

Use rclcpp::spin_some or wait_for_future inside the test body to process callbacks and futures. Initialize the context in SetUp with rclcpp::init and shut it down in TearDown to keep tests isolated.