Mockito throwing java.lang.NoClassDefFoundError and java.lan



我有这两个类(SimManager和Sim),我想创建它们的mock对象,然后使用它们的stub方法。

1  public class ContactTypeTest extends AndroidTestCase {
2  
3    @Override
4    public void setUp() throws Exception {
5      super.setUp();
6    
7      SimManager mockSimManager = mock(SimManager.class);
8      Sim mockSim = mock(Sim.class);
9       
10     when(mockSim.getOperator()).thenReturn("operator");
11     when(mockSim.getCircle()).thenReturn(circle);
12     when(mockSimManager.findSimBySerial("simSerial")).thenReturn(mockSim);
13    
14   }
15
16 }

测试在上面的第9行抛出了这两个错误跟踪。

第一个:

java.lang.VerifyError:org/mockito/cglib/core/ReflectUtilsorg.mockito.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:167)在org.mockito.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)在org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:217)在org.mockito.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)在org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:117)org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:109)org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:105)org.mockito.cglib.proxy.Enhancer.(Enhancer.java:70)org.mockito.internal.create.jmock.ClassImposterizer.createProxyClass(ClassImposterizer.java:85)在org.mockito.internal.create.jmock.ClassImposterizer.oimposterise(ClassImposterizer.java:62)在org.mockito.internal.create.jmock.ClassImposterizer.oimposterise(ClassImposterizer.java:56)在org.mockito.internal.create.CglibMockMaker.createMock(CglibMock Maker.java:23)网址:org.mockito.internal.util.MockUtil.createMock(MockUtil.java:26)org.mockito.internal.MockitoCore.mock(MockitoCore.java:51)org.mockito.Mokkito.mokk(mockito.java:1243)org.mockito.Mokkito.mock(mockito.java:1120)in.mubble.bi.test.core.message.ContactTypeTest.setUp(ContactTypeTest.java:25)在android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)在android.test.AndroidTestRunner.runTest(AndroidTestRunnr.java:176)在android.test.InstructionTestRunner.onStart(InstrumentationTestRunner.java:554)在android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1741)

第二:

java.lang.NoClassDefFoundError:org/mockito/internal/creation/jmock/ClassImposterizer$3org.mockito.internal.create.jmock.ClassImposterizer.createProxyClass(ClassImposterizer.java:85)在org.mockito.internal.create.jmock.ClassImposterizer.oimposterise(ClassImposterizer.java:62)在org.mockito.internal.create.jmock.ClassImposterizer.oimposterise(ClassImposterizer.java:56)在org.mockito.internal.create.CglibMockMaker.createMock(CglibMock Maker.java:23)网址:org.mockito.internal.util.MockUtil.createMock(MockUtil.java:26)org.mockito.internal.MockitoCore.mock(MockitoCore.java:51)org.mockito.Mokkito.mokk(mockito.java:1243)org.mockito.Mokkito.mock(mockito.java:1120)in.mubble.bi.test.core.message.ContactTypeTest.setUp(ContactTypeTest.java:25)在android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)在android.test.AndroidTestRunner.runTest(AndroidTestRunnr.java:176)在android.test.InstructionTestRunner.onStart(InstrumentationTestRunner.java:554)在android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1741)

我在libs文件夹中添加了mockito-all-1.9.5.jar,并将其添加到构建路径中。我不明白问题出在哪里。请帮忙。

我认为您必须使用Dexmaker

看看这个线程:

Mockito Android动态代理

相关内容

  • 没有找到相关文章

最新更新