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

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

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

无效尝试

常见但无效的做法:

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

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

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

    verify requires a method call to verify.