java
data_error
ai_generated
true
断言错误:期望 [1, 2, 3] 但实际是 [1, 2, 4]
java.lang.AssertionError: expected: [1, 2, 3] but was: [1, 2, 4]
ID: java/junit-assertion-expected-actual-mismatch
80%修复率
82%置信度
0证据数
2025-01-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 8+ | active | — | — | — |
根因分析
测试断言失败,因为期望值与实际值不匹配,通常由于测试数据或逻辑错误。
English
Test assertion failed due to mismatch between expected and actual values, often from incorrect test data or logic.
解决方案
-
90% 成功率 Use assertIterableEquals for lists
import static org.junit.jupiter.api.Assertions.assertIterableEquals; assertIterableEquals(expectedList, actualList);
-
85% 成功率 Debug by printing actual values
System.out.println("Actual: " + actualList); // Then fix production code
无效尝试
常见但无效的做法:
-
Changing expected value to match actual without investigation
80% 失败
Hides real bug in production code.
-
Ignoring order in lists without using appropriate matcher
60% 失败
AssertEquals checks order; using it for unordered lists causes false failures.