java
runtime_error
ai_generated
true
org.mockito.exceptions.misusing.UnnecessaryStubbingException: Unnecessary stubbings detected in test class
ID: java/mockito-strict-stubbing-unnecessary
80%Fix Rate
88%Confidence
0Evidence
2024-04-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 8+ | active | — | — | — |
Root Cause
Stubs defined with when() but never used during the test execution.
generic中文
使用 when() 定义的桩代码在测试执行过程中从未被使用。
Workarounds
-
85% success Use lenient() for specific stubs
lenient().when(mock.method()).thenReturn(value);
-
90% success Remove unused stubs
// Remove the stub line that is never used // when(mock.method()).thenReturn(value);
Dead Ends
Common approaches that don't work:
-
Removing all stubs blindly
50% fail
May cause test to fail if stubs were actually needed but not triggered.
-
Adding @MockitoSettings(strictness = Strictness.LENIENT) globally
40% fail
Hides real issues, may lead to false positives.