1

Trying to do a partial mock of an activity using Mockito.spy after its instrumented on the Android VM (Emulator 4.1). Here is the error I get

java.lang.VirtualMachineError
at dalvik.system.DexFile.defineClass(Native Method)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:207)
at dalvik.system.DexFile.loadClass(DexFile.java:196)
at dalvik.system.DexClassLoader.findClass(DexClassLoader.java:226)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at com.google.dexmaker.stock.ProxyBuilder.loadClass(ProxyBuilder.java:272)
at com.google.dexmaker.stock.ProxyBuilder.buildProxyClass(ProxyBuilder.java:254)
at com.google.dexmaker.mockito.DexmakerMockMaker.createMock(DexmakerMockMaker.java:54)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:26)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:49)
at org.mockito.Mockito.spy(Mockito.java:1324)
at com.company.droid.helper.ActivitySandbox.setupActivity(ActivitySandbox.java:21)
at com.company.droid.ui.fragment.signup.SignupFragmentTest.setUp(SignupFragmentTest.java:50)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)

I've tried changing VMs, Mockito versions, Dexmaker versions but nothing seems to work. Any ideas?

Rickster
  • 1,393
  • 3
  • 13
  • 19
  • 1
    Can you look in your log for any messages coming from Dalvik, especially at install or app startup time? You will generally get a bunch of spew that indicates (perhaps cryptically) a bit more detail about the problem. – danfuzz Oct 19 '12 at 00:14
  • I've recently switched from instrumentation tests to junit in pair with robolectric library. About spying - my observation it's usually issue with design. – Eugen Martynov Oct 20 '12 at 17:20
  • 1
    Tracking here: https://code.google.com/p/dexmaker/issues/detail?id=9 – Jesse Wilson Feb 10 '13 at 23:52
  • 2
    Looks like they included the fix in DexMaker 1.1, which was released this March. While the jars (`dexmaker-1.1` and `dexmaker-mockito-1.1`) are not currently hosted on the Google Code site, the site has links at the bottom to download them from the Maven repository. – JAB May 20 '14 at 19:14

1 Answers1

0

Seems to be a bug in Dalvik, which is not being avoided by DexMaker.

See this bug report and vote for it if you want. https://code.google.com/p/dexmaker/issues/detail?id=9

Andrew Mackenzie
  • 5,477
  • 5
  • 48
  • 70