java
runtime_error
ai_generated
true
org.mockito.exceptions.misusing.UnfinishedVerificationException: Missing method call for verify(mock) here:
ID: java/mockito-void-method-stub
80%Fix Rate
86%Confidence
0Evidence
2024-01-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 8+ | active | — | — | — |
Root Cause
Trying to stub a void method with when() instead of doNothing() or doThrow(), or verify syntax error.
generic中文
尝试使用 when() 而不是 doNothing() 或 doThrow() 来桩化 void 方法,或 verify 语法错误。
Workarounds
-
95% success Use doNothing() for void methods
doNothing().when(mock).voidMethod();
-
90% success Use doThrow() for void methods
doThrow(new RuntimeException()).when(mock).voidMethod();
Dead Ends
Common approaches that don't work:
-
Using when(mock.voidMethod()).thenReturn(value)
80% fail
void methods cannot return values; causes compilation or runtime error.
-
Using verify(mock) without method call
70% fail
verify requires a method call to verify.