qdrzwd / dexmaker

Automatically exported from code.google.com/p/dexmaker
0 stars 0 forks source link

Cant get dexmaker and mockito #16

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. try to use dexmaker and mockito via maven 
2.
3.

What is the expected output? What do you see instead?
dexmaker will do its magic and cglib will not be used

What version of the product are you using? On what operating system?
0.9 (without the -mockito since it has a "strange" dependency to mockito core 
1.9.8) 

Please provide any additional information below.
On intellij 11 and maven compiling agains android 4.1.x.x.
Maven:
 <dependency>
            <groupId>com.google.dexmaker</groupId>
            <artifactId>dexmaker</artifactId>
            <version>0.9</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.5</version>
        </dependency>

Since the it will not work if I use the dexmaker-mockito.
The dependency to mockito 1.9.8 core does not work. Shouldnt the dependency 
point to mockito 1.9.5 now? Then I guess I would only have to include that 
(dexmaker-moito with "correct" dependency) into my pom?
Or Have I misunderstood the whole thing? Do I really need to go the lib path 
with jars + manual handling of maven artefacts etc..?

I have followed the guide on 
http://www.paulbutcher.com/2012/05/mockito-on-android-step-by-step/
and it works. Now when all the updated releases are here and in the maven repos 
(http://search.maven.org/#artifactdetails%7Corg.mockito%7Cmockito-all%7C1.9.5%7C
jar) I was hoping that this should just work ...

The stacktrace:
java.lang.ExceptionInInitializerError
at 
org.mockito.internal.creation.jmock.ClassImposterizer.createProxyClass(ClassImpo
sterizer.java:85)
at 
org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposteri
zer.java:62)
at 
org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposteri
zer.java:56)
at 
org.mockito.internal.creation.CglibMockMaker.createMock(CglibMockMaker.java:23)
at 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 com.bacana.test.LoginActivityTest.testMockitoMock(LoginActivityTest.java:47)
at java.lang.reflect.Method.invokeNative(Native Method)
at 
android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at 
android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at 
android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTes
tCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at 
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:54
5)
at 
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551)
Caused by: java.lang.VerifyError: org/mockito/cglib/core/ReflectUtils
at 
org.mockito.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:167)
at 
org.mockito.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrateg
y.java:25)
at 
org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java
:217)
at org.mockito.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:117)
at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:109)
at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:105)
at org.mockito.cglib.proxy.Enhancer.<clinit>(Enhancer.java:70)

Original issue reported on code.google.com by nirr...@gmail.com on 15 Oct 2012 at 6:40

GoogleCodeExporter commented 8 years ago
Please try using mockito-1.9.5 and the new dexmaker-1.0 jar files.

Original comment by limpbizkit on 19 Oct 2012 at 9:28

GoogleCodeExporter commented 8 years ago
Hi, I am also experiencing this issue. I have followed the set-up instructions 
against Jesse Wilson's post, 
http://corner.squareup.com/2012/10/mockito-android.html.

Notably, Jesse indicates that there are 3 jars required;

1. dexmaker-1.0.jar
2. dexmaker-mockito-1.0.jar
3. mockito-all-1.9.5.jar

Does this go any distance to explaining the before mentioned stacktrace?

Original comment by oceanlif...@gmail.com on 24 Oct 2012 at 8:00

GoogleCodeExporter commented 8 years ago
Hi again.

Since I build/manage my Android applications with maven and I don't want to 
resort to include jars or setup my own repository with "special jars", I'm 
really looking forward to when the Dexmaker 1.0 with dependency to Mockito 
1.9.5 hits the public repositories.

Maven central haven't received them yet but I guess they will be up soon.

My wish is that if the maven artifact and the dependencies work then I should 
only have to include one dependency and then it should just work ;)

On a side note it does work via maven (as stated before) IF I setup a local 
repo and add the "special jars" - both via maven builds and in Intellij 11. I 
guess it would work with Eclipse to.

Oh, I think the stacktrace is simply because that setup won't work - dexmaker 
isn't "kicking in", since there are cglib references in the stacktrace.

Regards
Niclas

Original comment by nirr...@gmail.com on 24 Oct 2012 at 8:30

GoogleCodeExporter commented 8 years ago
Hi Niclas,

Thank you for your comment. I've posted something on SO 
(http://stackoverflow.com/questions/13048985/verifyerror-using-mockito-1-9-5-and
-dexmaker-mockito-1-0) to share the problem and post a solution as and when one 
appears! If I had a penny for everytime I started TDD on Android and failed! :S

Regards,
David 

Original comment by oceanlif...@gmail.com on 24 Oct 2012 at 1:04

GoogleCodeExporter commented 8 years ago
Answered my own question on SO if you were interested Niclas. Obviously I 
didn't understand that the emulator was not good enough for this 
android-mockito implementation. Still missing something but glad I have a 
mocking framework in Android!  

Original comment by oceanlif...@gmail.com on 25 Oct 2012 at 10:23

GoogleCodeExporter commented 8 years ago
Maybe I have misunderstood something but ...
I have Dexmaker and Mockito working with the help of maven BUT via the "special 
jars" installed locally in my local maven repo from 
http://www.paulbutcher.com/2012/05/mockito-on-android-step-by-step/, running on 
an android 2.3 emulator (!).

Since I'm using "old" versions of both dexmaker and mockito I have the 
following in my tests setup method: 
getInstrumentation().getTargetContext().getCacheDir(); (This statement should 
not be needed in the dexmaker 0.9+ release though ...)
After that statement I have mock(SomeClass.class, RETURNS_DEEP_STUBS) and 
mock(SomeOtherClass.class) and they work in IntelliJ 11 and if I run them via 
maven.

But as I mentioned in the previous post, I really don't want to do all theses 
special things. I don't want to introduce any special environment setups. It 
should just work with one or two maven dependencies ;)

/niclas

Original comment by nirr...@gmail.com on 25 Oct 2012 at 2:55