java MockitoInvocationHandler 类的 NoClassDefFoundError
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12157559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NoClassDefFoundError for MockitoInvocationHandler class
提问by sura watthana
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.
我正在使用mockito-all-1.9.5-rc1.jar
和powermock-mockito-1.4.12-full.jar
。当我运行这个简单的单元测试来模拟非最终类中的最终方法时。
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());
}
}
When I ran it, I got
java.lang.NoClassDefFoundError: org/mockito/internal/MockitoInvocationHandler
Caused by: java.lang.ClassNotFoundException: org.mockito.internal.MockitoInvocationHandler
当我运行它时,我得到了
java.lang.NoClassDefFoundError: org/mockito/internal/MockitoInvocationHandler
Caused by: java.lang.ClassNotFoundException: org.mockito.internal.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
当我MockitoInvocationHandler
在mockito-all-1.9.5-rc1.jar
和 中搜索 fo 类时powermock-mockito-1.4.12-full.jar
。我找不到任何。需要帮助解决这个问题!谢谢
回答by Brice
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.
Mockito 1.9.5-rc1 必须在内部重构以允许第三方模拟制造商。MockitoInvocationHandler
一直到 Mockito 1.9.0 都是 Mockito 内部结构的一部分(正如包名所暗示的那样)。
Due to these changes, currentsome older version Powermock releases as of todayare not compatible with the latest Mockito release.
由于这些变化,截至今天,当前一些较旧版本的 Powermock 版本与最新的 Mockito 版本不兼容。
Another reason to avoid mocking/stubbing finals or statics ;)
避免嘲笑/存根决赛或静态的另一个原因;)
Hope that helps Cheers,
希望能帮助干杯,