stephanenicolas/Quality-Tools-for-Android

EasyMock / java.lang.NoClassDefFoundError: com/google/dexmaker/stock/ProxyBuilder

franck-serot opened this issue · 1 comments

Hi,
I studied the sample android-sample-robolectric-tests.
I tried to create an android-demo project with a simple HelloWorld Activity and a button in order to display the current date in a Toast when the button is clicked.
I could implemented some tests like your sample but I have a problem with EasyMock.
I used the same version of the testing librairies than your sample.

My problem is when I try to mock a class from my Android projet or a simple class like String.
For example :
HelperDate mockHelperDate = EasyMock.createMock(HelperDate.class);
The error is below.

I tried to add the librairy dexmaker v1.0 but I had an other error because no device is connected. If I understand dexmarker is required for test on device.
Could you please help to solve my problem ?
Best regards,
Franck

java.lang.NoClassDefFoundError: com/google/dexmaker/stock/ProxyBuilder
at org.easymock.internal.AndroidClassProxyFactory.createProxy(AndroidClassProxyFactory.java:40)
at org.easymock.internal.MocksControl.createMock(MocksControl.java:114)
at org.easymock.internal.MocksControl.createMock(MocksControl.java:88)
at org.easymock.internal.MocksControl.createMock(MocksControl.java:79)
at org.easymock.EasyMock.createMock(EasyMock.java:136)
at com.orange.demo.HelloAndroidActivityTest.shouldGetDateUsingEasyMock(HelloAndroidActivityTest.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:234)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:175)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: com.google.dexmaker.stock.ProxyBuilder
at org.robolectric.bytecode.AsmInstrumentingClassLoader.findClass(AsmInstrumentingClassLoader.java:119)
at org.robolectric.bytecode.AsmInstrumentingClassLoader.loadClass(AsmInstrumentingClassLoader.java:95)
... 31 more

I found the explanation of this problem.
I tried to mock a class instead of an interface with Easymock.

I've just replaced this line
HelperDate mockHelperDate = EasyMock.createMock(HelperDate.class);
by
HelperDate mockHelperDate = EasyMock.createMock(IHelperDate.class);
with IHelperDate an interface implemented by HelperDate.

This issue can be closed.