org.mockito.exceptions.misusing.PotentialStubbingProblem:Strict stubbing argument mismatch

org.mockito.exceptions.misusing.PotentialStubbingProblem:
Strict stubbing argument mismatch. Please check:

Typically, stubbing argument mismatch indicates user mistake when writing tests.
Mockito fails early so that you can debug potential problem easily.
However, there are legit scenarios when this exception generates false negative signal:

  • stubbing the same method multiple times using ‘given().will()’ or ‘when().then()’ API
    Please use ‘will().given()’ or ‘doReturn().when()’ API for stubbing.
  • stubbed method is intentionally invoked with different arguments by code under test
    Please use default or ‘silent’ JUnit Rule (equivalent of Strictness.LENIENT).
    For more information see javadoc for PotentialStubbingProblem class.
11.2 异常信息
org.mockito.exceptions.misusing.PotentialStubbingProblem: 
Strict stubbing argument mismatch. Please check:
 - this invocation of 'getWithCache' method:
    serviceFacade.getWithCache(
    "code"
);
    -> at com.xxx.lambda$getService$3(xxx.java:132)
 - has following stubbing(s) with different arguments:
    1. serviceFacade.getWithCache(
     "code"
);
      -> at com.xxxTest.should_xxx_successfully(xxxTest.java:89)
    2. serviceFacade.getWithCache(
     "code"
);
      -> at com.xxxTest.should_xxx_successfully(xxxTest.java:94)
Typically, stubbing argument mismatch indicates user mistake when writing tests.
Mockito fails early so that you can debug potential problem easily.
However, there are legit scenarios when this exception generates false negative signal:
  - stubbing the same method multiple times using 'given().will()' or 'when().then()' API
    Please use 'will().given()' or 'doReturn().when()' API for stubbing.
  - stubbed method is intentionally invoked with different arguments by code under test
    Please use default or 'silent' JUnit Rule (equivalent of Strictness.LENIENT).
For more information see javadoc for PotentialStubbingProblem class.
  • when(mock.someMethod(any())).thenReturn(“output1”);
  • when(mock.someMethod(eq(“input2”))).thenReturn(“output2”);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值