Mockito抛出java.lang.NoClassDefFoundError和java.lang.VerifyError

时间:2014-11-04 10:04:58

标签: java android eclipse unit-testing mockito

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

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 / ReflectUtils at at   org.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)at   org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:109)at at   org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:105)at at   org.mockito.cglib.proxy.Enhancer。(Enhancer.java:70)at   org.mockito.internal.creation.jmock.ClassImposterizer.createProxyClass(ClassImposterizer.java:85)   在   org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:62)   在   org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:56)   在   org.mockito.internal.creation.CglibMockMaker.createMock(CglibMockMaker.java:23)   在org.mockito.internal.util.MockUtil.createMock(MockUtil.java:26)at   org.mockito.internal.MockitoCore.mock(MockitoCore.java:51)at   org.mockito.Mockito.mock(Mockito.java:1243)at   org.mockito.Mockito.mock(Mockito.java:1120)at   in.mubble.bi.test.core.message.ContactTypeTest.setUp(ContactTypeTest.java:25)   在android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)   在android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)   在   android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)   在   android.app.Instrumentation $ InstrumentationThread.run(Instrumentation.java:1741)

第二

  

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

我在我的libs文件夹中添加了mockito-all-1.9.5.jar,并将其添加到构建路径中。我不明白这个问题是什么。请帮助。

1 个答案:

答案 0 :(得分:1)

我认为您必须使用 Dexmaker

看一下这个帖子:

Mockito Android dynamic proxies