java
runtime_error
ai_generated
true
未完成的桩代码检测:doReturn().when() 未完成
org.mockito.exceptions.misusing.UnfinishedStubbingException: Unfinished stubbing detected here: doReturn().when()
ID: java/mockito-doreturn-when-mismatch
80%修复率
85%置信度
0证据数
2024-02-28首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 8+ | active | — | — | — |
根因分析
doReturn().when() 语法使用不正确,例如缺少方法调用或顺序错误。
English
doReturn().when() syntax is used incorrectly, such as missing method call or wrong order.
解决方案
-
90% 成功率 Complete the doReturn().when() chain correctly
doReturn("value").when(mock).method(); -
85% 成功率 Use when().thenReturn() for non-void methods
when(mock.method()).thenReturn("value");
无效尝试
常见但无效的做法:
-
Switching to when().thenReturn() blindly
50% 失败
May not work for void methods or spies.
-
Adding extra doReturn calls
60% 失败
Compounds the issue; still unfinished.