MockitoInvocationHandler类的NoClassDefFoundError [英] NoClassDefFoundError for MockitoInvocationHandler class

查看:200
本文介绍了MockitoInvocationHandler类的NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mockito-all-1.9.5-rc1.jarpowermock-mockito-1.4.12-full.jar. 当我运行此简单的单元测试来模拟非最终类中的最终方法时.

I am using mockito-all-1.9.5-rc1.jar and powermock-mockito-1.4.12-full.jar. When I run this simple unit test for mocking final method in non-final class.

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest(ABC.class)
public class ABCTest {

    @Test
    public void finalCouldBeMock() {
        final ABC abc = PowerMockito.mock(ABC.class);
        PowerMockito.when(abc.myMethod()).thenReturn("toto");
        assertEquals("toto", abc.myMethod());
    }

}

当我运行它时,我得到了 java.lang.NoClassDefFoundError: org/mockito/internal/MockitoInvocationHandler Caused by: java.lang.ClassNotFoundException: org.mockito.internal.MockitoInvocationHandler

When I ran it, I got java.lang.NoClassDefFoundError: org/mockito/internal/MockitoInvocationHandler Caused by: java.lang.ClassNotFoundException: org.mockito.internal.MockitoInvocationHandler

当我在mockito-all-1.9.5-rc1.jarpowermock-mockito-1.4.12-full.jar中搜索类MockitoInvocationHandler时.我找不到. 在这个问题上需要帮助!谢谢

When I search fo class MockitoInvocationHandler in mockito-all-1.9.5-rc1.jar and powermock-mockito-1.4.12-full.jar. I couldn't find any. Need help with this issue! Thank you

推荐答案

Mockito 1.9.5-rc1必须在内部进行重构,以允许第三方模拟程序制造商. MockitoInvocationHandler是Mockito 1.9.0之前的Mockito内部组件(如程序包名称所示).

Mockito 1.9.5-rc1 had to be refactored internally to allow third party mock maker. MockitoInvocationHandler was part of the Mockito's internals (as the package name suggests) up to Mockito 1.9.0.

由于这些更改,当前某些较早版本的Powermock截至今天的 与最新的Mockito版本不兼容.

Due to these changes, current some older version Powermock releases as of today are not compatible with the latest Mockito release.

避免模拟/加粗finals或statics的另一个原因;)

Another reason to avoid mocking/stubbing finals or statics ;)

希望有帮助 干杯,

这篇关于MockitoInvocationHandler类的NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆