java runtime_error ai_generated true

org.mockito.exceptions.misusing.UnfinishedVerificationException: Missing method call for verify(mock) here:

ID: java/mockito-void-method-stub

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2024-01-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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

  1. 95% success Use doNothing() for void methods
    doNothing().when(mock).voidMethod();
  2. 90% success Use doThrow() for void methods
    doThrow(new RuntimeException()).when(mock).voidMethod();

Dead Ends

Common approaches that don't work:

  1. Using when(mock.voidMethod()).thenReturn(value) 80% fail

    void methods cannot return values; causes compilation or runtime error.

  2. Using verify(mock) without method call 70% fail

    verify requires a method call to verify.