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

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

generic

解决方案

  1. 90% 成功率 Complete the doReturn().when() chain correctly
    doReturn("value").when(mock).method();
  2. 85% 成功率 Use when().thenReturn() for non-void methods
    when(mock.method()).thenReturn("value");

无效尝试

常见但无效的做法:

  1. Switching to when().thenReturn() blindly 50% 失败

    May not work for void methods or spies.

  2. Adding extra doReturn calls 60% 失败

    Compounds the issue; still unfinished.