# colcon测试：返回码2。部分测试失败。详情见输出。

- **ID:** `ros2/colcon-test-return-code-2`
- **领域:** ros2
- **类别:** test_error
- **错误码:** `2`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

ROS2包中的一个或多个测试用例返回非零退出状态，通常由断言失败、缺少依赖或测试执行期间的运行时异常导致。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Humble | active | — | — |
| Iron | active | — | — |
| Jazzy | active | — | — |
| Rolling | active | — | — |

## 解决方案

1. ```
   Run colcon test with --event-handlers console_direct+ to see detailed test output and identify failing tests.
   ```
2. ```
   Check test log files in 'log/test_*' directory for specific failure messages.
   ```
3. ```
   Update test dependencies in package.xml and run 'rosdep install -i --from-paths src' to ensure all test packages are installed.
   ```

## 无效尝试

- **Re-running colcon test without cleaning build artifacts** — Stale test binaries or cached results may mask underlying failures; a clean rebuild is needed. (40% 失败率)
- **Disabling all tests with --packages-select and --mixin skip-tests** — This bypasses the problem without fixing it, leaving broken tests for later. (80% 失败率)
- **Upgrading colcon-core to latest version** — The error is test-logic related, not a colcon tool bug. (30% 失败率)
