lishunli / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

Support PowerMock to run Android JUNIT tests #539

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Try to mock any Android final class

What is the expected output? What do you see instead?
Expect the class to get mocked.

What version of the product are you using? On what operating system?
1.6.1 on Win7 64 bit and running against Android 4.0 (API 16)

Please provide any additional information below.
I get the below stack trace. Apparently PowerMock uses javaassist to modify 
byte codes, however since Android uses DEX code, can PowerMock be modified to 
work with dexmaker-1.0.jar and dexmaker-mockito-1.0.jar similar to how Mockito 
does it ?

java.lang.ExceptionInInitializerError
at 
org.mockito.internal.creation.jmock.ClassImposterizer.createProxyClass(ClassImpo
sterizer.java:96)
at 
org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposteri
zer.java:60)
at 
org.powermock.api.mockito.internal.mockcreation.MockCreator.createMethodInvocati
onControl(MockCreator.java:109)
at 
org.powermock.api.mockito.internal.mockcreation.MockCreator.mock(MockCreator.jav
a:57)
at org.powermock.api.mockito.PowerMockito.mock(PowerMockito.java:143)
at 
com.mcafee.endpointassist.test.unit.service.TestBluetoothConnectionListener.setU
p(TestBluetoothConnectionListener.java:49)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at 
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:55
5)
at 
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)
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)
... 15 more

Original issue reported on code.google.com by shashank.visweswara@gmail.com on 9 Feb 2015 at 12:08

GoogleCodeExporter commented 9 years ago
I think this might be similar, but I'm getting the below exception : 
java.lang.VerifyError: org/mockito/cglib/core/ReflectUtils

which occurs with a failure to setup: dexmaker-1.0.jar and 
dexmaker-mockito-1.0.jar
However I HAVE set those up properly, because my exissting mockito tests work 
fine. Power mock seems to be ignoring them.

---------

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)
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.powermock.api.mockito.internal.mockcreation.MockCreator.createMethodInvocati
onControl(MockCreator.java:109)
at 
org.powermock.api.mockito.internal.mockcreation.MockCreator.mock(MockCreator.jav
a:57)
at org.powermock.api.mockito.PowerMockito.mockStatic(PowerMockito.java:70)
at tests.ExampleTest.testRegisterService(ExampleTest.java:186)
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.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at 
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:55
4)
at 
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)

Original comment by john.tw...@gmail.com on 24 Feb 2015 at 10:01