# 断言错误：期望 [1, 2, 3] 但实际是 [1, 2, 4]

- **ID:** `java/junit-assertion-expected-actual-mismatch`
- **领域:** java
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

测试断言失败，因为期望值与实际值不匹配，通常由于测试数据或逻辑错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 8+ | active | — | — |

## 解决方案

1. **Use assertIterableEquals for lists** (90% 成功率)
   ```
   import static org.junit.jupiter.api.Assertions.assertIterableEquals;
assertIterableEquals(expectedList, actualList);
   ```
2. **Debug by printing actual values** (85% 成功率)
   ```
   System.out.println("Actual: " + actualList);
// Then fix production code
   ```

## 无效尝试

- **Changing expected value to match actual without investigation** — Hides real bug in production code. (80% 失败率)
- **Ignoring order in lists without using appropriate matcher** — AssertEquals checks order; using it for unordered lists causes false failures. (60% 失败率)
