Files
ros2-assignments/doc/tests/WheelDataSimulator.md

74 lines
2.3 KiB
Markdown

# Wheel Data Simulator Unit Tests
Unit tests for the `DataSimulator` (Wheel) node are implemented in `src/g2_2025_odometry_pkg/test/test_wheel_simulator.cpp` using Google Test and ROS2 test utilities. The tests validate node initialization, message publishing, array structure, and data correctness.
## Test Cases
### 1. NodeInitialization
**Description:** Verifies that the Wheel DataSimulator node can be created without errors.
- **Test Action:** Create DataSimulator instance
- **Expected Result:** No exceptions thrown during construction
### 2. WheelDataPublishing
**Description:** Tests that wheel data messages are published on the correct topic.
- **Test Action:**
- Create subscription to `simulated_wheel_data` topic
- Create DataSimulator node
- Spin both nodes for a short period
- **Expected Result:** At least one `std_msgs/msg/Float64MultiArray` message is received
### 3. WheelDataArraySize
**Description:** Verifies that the published array contains the correct number of wheel values.
- **Test Action:**
- Subscribe to `simulated_wheel_data`
- Receive a message
- Check array size
- **Expected Result:** `data.size()` equals 4 (FL, FR, RL, RR)
### 4. ValidVelocityValues
**Description:** Tests that all wheel velocity values are valid (finite numbers).
- **Test Action:**
- Subscribe and receive wheel data message
- Check each value in the array
- **Expected Result:** All 4 values are finite numbers
### 5. MultipleMessagesReceived
**Description:** Tests that multiple messages are published over time.
- **Test Action:**
- Subscribe and count received messages
- Spin for a short duration
- **Expected Result:** Message count is greater than 0
## Test Infrastructure
The test class `WheelSimulatorTest` provides:
- Static `SetUpTestSuite()` and `TearDownTestSuite()` for ROS2 init/shutdown
- Helper method `setupBasicWheelParams()` for setting up default test parameters
## ROS2 Topics Used
| Topic | Message Type | Direction |
|-------|--------------|-----------|
| `simulated_wheel_data` | std_msgs/msg/Float64MultiArray | Published by node under test |
## Data Array Format
The published Float64MultiArray contains wheel values in the following order:
| Index | Wheel |
|-------|-------|
| 0 | Front Left (FL) |
| 1 | Front Right (FR) |
| 2 | Rear Left (RL) |
| 3 | Rear Right (RR) |