java runtime_error ai_generated true

org.mockito.exceptions.misusing.UnfinishedStubbingException: Unfinished stubbing detected here: doReturn().when()

ID: java/mockito-doreturn-when-mismatch

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-02-28First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
8+ active

Root Cause

doReturn().when() syntax is used incorrectly, such as missing method call or wrong order.

generic

中文

doReturn().when() 语法使用不正确,例如缺少方法调用或顺序错误。

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. Switching to when().thenReturn() blindly 50% fail

    May not work for void methods or spies.

  2. Adding extra doReturn calls 60% fail

    Compounds the issue; still unfinished.