Mockito 3.11.0 seems to fail in Android instrumentation tests
See original GitHub issueAfter upgrading from 3.10.0 to 3.11.0, our instrumentation tests started failing with a strange error about Mockito plugins:
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
at org.mockito.internal.configuration.plugins.PluginLoader$1.invoke(PluginLoader.java:84)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy12.isTypeMockable(Unknown Source)
at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:33)
at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22)
at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:250)
at org.mockito.internal.creation.MockSettingsImpl.build(MockSettingsImpl.java:232)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:83)
at org.mockito.Mockito.mock(Mockito.java:1954)
at org.mockito.Mockito.mock(Mockito.java:1865)
at com.blueapron.service.mock.ServiceTestApplication$1.mock(ServiceTestApplication.java:29)
at com.blueapron.testcommon.StaticMock.provide(StaticMock.java:42)
at com.blueapron.service.mock.InstrumentAppModule.provideClock_impl(InstrumentAppModule.java:55)
at com.blueapron.service.dagger.ApplicationModule.provideClock(ApplicationModule.java:230)
at com.blueapron.service.dagger.ApplicationModule_ProvideClockFactory.provideClock(ApplicationModule_ProvideClockFactory.java:35)
at com.blueapron.service.dagger.ApplicationModule_ProvideClockFactory.get(ApplicationModule_ProvideClockFactory.java:27)
at com.blueapron.service.dagger.ApplicationModule_ProvideClockFactory.get(ApplicationModule_ProvideClockFactory.java:9)
at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
at com.blueapron.service.mock.DaggerInstrumentApplicationComponent.injectTimeUtils(DaggerInstrumentApplicationComponent.java:653)
at com.blueapron.service.mock.DaggerInstrumentApplicationComponent.inject(DaggerInstrumentApplicationComponent.java:345)
at com.blueapron.marinator.generated.MarinadeHelper.inject(MarinadeHelper.java:254)
at com.blueapron.marinator.Marinator.inject(Marinator.java:50)
at com.blueapron.service.util.TimeUtils.<init>(TimeUtils.java:34)
at com.blueapron.service.util.TimeUtils.getInstance(TimeUtils.java:40)
at com.blueapron.service.util.TimeUtils.getClock(TimeUtils.java:47)
at com.blueapron.service.BaseInstrumentationTest.setDateForTest(BaseInstrumentationTest.java:54)
at com.blueapron.service.BaseInstrumentationTest.initBase(BaseInstrumentationTest.java:71)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at androidx.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:76)
at androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)
at com.blueapron.testcommon.FlakyTestRule$1.evaluate(FlakyTestRule.java:30)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:154)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:395)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2189)
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in sun.misc.CompoundEnumeration@f915e73
at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:57)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:65)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:50)
at org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:26)
at org.mockito.internal.configuration.plugins.Plugins.<clinit>(Plugins.java:20)
at org.mockito.internal.configuration.plugins.Plugins.getMockMaker(Plugins.java:36)
at org.mockito.internal.util.MockUtil.<clinit>(MockUtil.java:28)
... 59 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:52)
... 65 more
Caused by: java.lang.IllegalStateException: Failed to resolve the class file version of the current VM: This JVM's version string does not seem to be valid: 0
at net.bytebuddy.ClassFileVersion$VersionLocator$Unresolved.resolve(ClassFileVersion.java:558)
at net.bytebuddy.ClassFileVersion.ofThisVm(ClassFileVersion.java:276)
at net.bytebuddy.description.method.ParameterList$ForLoadedExecutable.of(ParameterList.java:205)
at net.bytebuddy.description.method.MethodDescription$ForLoadedMethod.getParameters(MethodDescription.java:1179)
at net.bytebuddy.implementation.bind.annotation.TargetMethodAnnotationDrivenBinder.compile(TargetMethodAnnotationDrivenBinder.java:82)
at net.bytebuddy.implementation.MethodDelegation$ImplementationDelegate$ForStaticMethod.of(MethodDelegation.java:948)
at net.bytebuddy.implementation.MethodDelegation$WithCustomProperties.to(MethodDelegation.java:1512)
at net.bytebuddy.implementation.MethodDelegation$WithCustomProperties.to(MethodDelegation.java:1493)
at net.bytebuddy.implementation.MethodDelegation.to(MethodDelegation.java:271)
at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.<init>(SubclassBytecodeGenerator.java:63)
at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.<init>(SubclassBytecodeGenerator.java:73)
at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.<init>(SubclassByteBuddyMockMaker.java:37)
at org.mockito.android.internal.creation.AndroidByteBuddyMockMaker.<init>(AndroidByteBuddyMockMaker.java:22)
... 68 more
It looks like something may not quite play nicely with the Android ByteBuddy MockMaker in the newest versions?
In our instrumentation tests, we’re using androidTestImplementation org.mockito:mockito-android:3.11.0
. Our unit tests using testImplementation org:mockito:mockito-core:3.11.0
appear to be working just fine, which is why I suspect something is off in the Android specific implementation.
I’m not sure how best to debug this further - is there additional information that would be useful?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:9
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Mockito upgrade 3.10 to 3.11 causes crash - Stack Overflow
I just upgraded Mockito from 3.10.0 to 3.11.0 in our Android project, and now, running instrumentation tests crashes with the exception ...
Read more >Mockito 3.11.0 API - javadoc.io
New API for integrations: MockitoSession is usable by testing frameworks (Since 2.15.+) ... To enable Android support, add the `mockito-android` library as ...
Read more >Developing Android unit and instrumentation tests - Tutorial
This tutorial describes how to write unit and instrumentation tests for your Android application. It describes how to execute these tests via Android...
Read more >org.mockito » mockito-core » 3.11.0 - Maven Repository
Mockito Core » 3.11.0. Mockito mock objects library core API and implementation ... HomePage, https://github.com/mockito/mockito. Date, Jun 03, 2021.
Read more >Test - Android Developers
For earlier updates that appeared in the support library see the archive page. Declaring dependencies. To add a dependency on androidx.test, you must...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I faced with the same error, how I can fix it?
Mockito is the only one lib in the project which uses Byte Buddy (1.11.3). I just realized that the stack trace is different that the original one for this issue, so I created a new issue: https://github.com/mockito/mockito/issues/2355