Issue
I am using Mockito to mock classes for Android testing. It behaves as expected when mocking any given class, except WebView (as far as I have seen in my code). When attempting to mock a WebView using:
mock(WebView.class);
I receive the following stacktrace:
java.lang.VirtualMachineError
at dalvik.system.DexFile.defineClass(Native Method)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:211)
at dalvik.system.DexPathList.findClass(DexPathList.java:305)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:62)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
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:56)
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.ncsa.clientrms.navigation.WebFragment2Test.setUp(WebFragment2Test.java:19)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)
I have looked at this post, which might indicate these two situations stem from the same bug, especially since the stack traces are nearly identical. Is there something I can do to resolve this?
On a side note, is Mockito being maintained? I would rather not be tied to a dependency from 2012.
Solution
I was having a similar issue on creating mocks using mockito for classes derived from FrameLayout and also for those from GridView.
As per the comment on the other post you mentioned, this issue has been fixed in version 1.1 of dexmaker and dexmaker-mockito.
These libs can be downloaded here and included in your libs directory. Just be sure to clean and rebuild to ensure that updated version 1.1 libs are used. I have seen issues where Android Studio was still picking up the previous versions of the libs. A manual delete of the bin folders in my project resolved this.
Answered By - Jadent
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.