有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (1) 个答案

  1. # 1 楼答案

    你检查了MissingMethodInvocationException异常消息了吗

    上面写着:

    when() requires an argument which has to be 'a method call on a mock'.
    For example:
        when(mock.getArticles()).thenReturn(articles);
    
    Also, this error might show up because:
    1. you stub either of: final/private/equals()/hashCode() methods.
       Those methods *cannot* be stubbed/verified.
    2. inside when() you don't call method on mock but on some other object.
    3. the parent of the mocked class is not public.
       It is a limitation of the mock engine.
    

    要么类Level是最终的(显然不像我记得扩展这个类那样),要么getSyslogEquivalent是最终的(最佳猜测)

    因此,您应该修改设计或测试设计,或者尝试Powermock,它提供了最终的类/方法模拟

    希望有帮助