java
runtime_error
ai_generated
true
参数匹配器使用无效:预期 0 个匹配器,但记录了 1 个
org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers! 0 matchers expected, 1 recorded
ID: java/mockito-wrong-type-argument
80%修复率
86%置信度
0证据数
2024-06-12首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 8+ | active | — | — | — |
根因分析
在同一方法调用中混合使用匹配器和精确值,或在 when/verify 之外使用匹配器。
English
Mixing matchers and exact values in same method call, or using matchers outside of when/verify.
解决方案
-
95% 成功率 Use matchers for all parameters consistently
when(mock.method(anyString(), anyInt())).thenReturn(value);
-
90% 成功率 Use eq() for exact values with matchers
when(mock.method(eq("exact"), anyInt())).thenReturn(value);
无效尝试
常见但无效的做法:
-
Using any() for all parameters
50% 失败
May cause UnnecessaryStubbingException if not all used.
-
Removing matchers and using exact values only
40% 失败
Reduces test flexibility; may not match actual calls.