添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
宽容的山楂  ·  喵绅士_哔哩哔哩_bilibili·  4 月前    · 
踏实的风衣  ·  Recherche·  4 月前    · 
骑白马的菠菜  ·  mt798x uboot 功能介绍·  5 月前    · 

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

最新推荐文章于 2024-08-14 23:30:40 发布
最新推荐文章于 2024-08-14 23:30:40 发布 阅读量1.6k

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”);
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 一个 python 文件中只能初始化一个节点。 我在一个 python 文件中导入了另一个 module,在另一个 module 中的类的初始化函数中存在一个: rospy.init_node() 在调用这个类时,这与 main 函数所在的 python 文件中的 rospy.init_node() 冲突。 3. 解决方法 我删除了 module import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; im...
org.mockito.exceptions.misusing.UnfinishedStubbingException: Unfinished stubbing detected here: 可能不在堆栈报错的对应的mock上. 这个是最坑的点.   对公司项目的底层依赖包进行升级,在运行成功后打包时出现了问题,测试无法通过,抛出异常: org.mockito.exceptions.misusing.NotAMockException: Argument should be a mock, but is: class java.lang.Class at com.eastmoney.emis.service.IPOServiceTest.getEmptyContentTest(IPOServiceTest.java:132)
org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Misplaced or misused argument matcher detected here: -> at xxxxxxxxxxxxxxxxxxxxxxxx You cannot use argument matchers outside of verification or stubbing. Examples of correct usage of arg.
org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers! 2 matchers expected, 1 recorded: -> at com.didi.bigdata.tag.control.DTagOuterControllerTest.lockDta...
什么是Mock 参考 使用Mockito进行单元测试【1】——mock and verify讲的好清楚明白 mock其实是一种工具的简称,他最大的功能是帮你把单元测试的耦合分解开,如果你的代码对另一个类或者接口有依赖,它能够帮你模拟这些依赖,并帮你验证所调用的依赖的行为。 什么是mockito mockito是一种mock工具 ,它使用执行后验证的模型,语法更简洁并且更加贴近程序员的思考方式,能够模拟类而不仅仅是接口等等
org.mockito.exceptions.misusing.invaliduseofmatchersexceptionMockito框架中的一个异常,表示在使用Matcher时出现了错误的用法。Matcher是Mockito框架中的一个重要概念,用于匹配方法参数,从而实现对方法的模拟。如果在使用Matcher时出现了错误的用法,就会抛出这个异常。通常情况下,这个异常的出现是由于Mockito的使用者没有正确地使用Matcher,或者使用了不支持的Matcher导致的。为了避免这个异常的出现,我们需要仔细阅读Mockito的文档,并且正确地使用Matcher。