【问题标题】:Mockito Inline Mock Maker - throws Exception - Argument passed to when() is not a mockMockito Inline Mock Maker - 抛出异常 - 传递给 when() 的参数不是模拟
【发布时间】:2021-04-05 06:24:04
【问题描述】:

我想模拟静态方法,因此使用依赖“mockito-inline”3.8 版本而不是“mockito-core”

静态方法模拟工作正常,但我模拟接口的旧测试失败并出现以下错误

org.mockito.exceptions.misusing.NotAMockException: 
Argument passed to when() is not a mock!
Example of correct stubbing:
    doThrow(new RuntimeException()).when(mock).someMethod();

恢复使用 mockito-core 解决了这个问题,但我无法模拟静态方法

有什么方法可以为每个类选择不同的模拟引擎(子类/内联)?

【问题讨论】:

    标签: unit-testing mockito


    【解决方案1】:

    MockResolver 修复了https://github.com/mockito/mockito/issues/1980 中所述的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-27
      • 2022-07-29
      • 1970-01-01
      相关资源
      最近更新 更多