• org.mockito.exceptions.misusing.CannotStubVoidMethodWithReturnValue


    错误原因:mock的时候,不能mock重载的方法

    解决方法:直接mock它的父类的方法

    org.mockito.exceptions.misusing.CannotStubVoidMethodWithReturnValue:
    'flush' is a *void method* and it *cannot* be stubbed with a *return value*!
    Voids are usually stubbed with Throwables:
    doThrow(exception).when(mock).someVoidMethod();
    ***
    If you're unsure why you're getting above error read on.
    Due to the nature of the syntax above problem might occur because:
    1. The method you are trying to stub is *overloaded*. Make sure you are calling the right overloaded version.
    2. Somewhere in your test you are stubbing *final methods*. Sorry, Mockito does not verify/stub final methods.
    3. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies -
    - with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.
    4. Mocking methods declared on non-public parent classes is not supported.

  • 相关阅读:
    exchangeNetwork
    VRP OS Management
    filleSystemBasises
    Study_way
    1.MySQL 安装
    7.进程池与线程池
    6.线程
    5.进程 -锁
    4.进程-1
    3.多线程TCP协议与加密方式
  • 原文地址:https://www.cnblogs.com/nizuimeiabc1/p/6496701.html
Copyright © 2020-2023  润新知