java
runtime_error
ai_generated
true
未完成的验证异常:此处 verify(mock) 缺少方法调用
org.mockito.exceptions.misusing.UnfinishedVerificationException: Missing method call for verify(mock) here:
ID: java/mockito-void-method-stub
80%修复率
86%置信度
0证据数
2024-01-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 8+ | active | — | — | — |
根因分析
尝试使用 when() 而不是 doNothing() 或 doThrow() 来桩化 void 方法,或 verify 语法错误。
English
Trying to stub a void method with when() instead of doNothing() or doThrow(), or verify syntax error.
解决方案
-
95% 成功率 Use doNothing() for void methods
doNothing().when(mock).voidMethod();
-
90% 成功率 Use doThrow() for void methods
doThrow(new RuntimeException()).when(mock).voidMethod();
无效尝试
常见但无效的做法:
-
Using when(mock.voidMethod()).thenReturn(value)
80% 失败
void methods cannot return values; causes compilation or runtime error.
-
Using verify(mock) without method call
70% 失败
verify requires a method call to verify.