question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mockito-android fails with AndroidStudio 4

See original GitHub issue

Env

Using:

  • mockito 3.3.3:

    • androidTestImplementation "org.mockito:mockito-android:$mockito"
    • testImplementation "org.mockito:mockito-core:$mockito"
  • Android Studio 4.0

  • kotlin 1.3.72.

Description

Having androidTestImplementation "org.mockito:mockito-android:$mockito" in gradle causes the unit test (which is not what androidTestImplementation is intended for) to fail when I call mock function I get an error on MockMaker:

Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
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:74)
	at com.sun.proxy.$Proxy2.isTypeMockable(Unknown Source)
	at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:29)
	at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22)
	at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:241)
	at org.mockito.internal.creation.MockSettingsImpl.build(MockSettingsImpl.java:229)
	at org.mockito.internal.MockitoCore.mock(MockitoCore.java:62)
	at org.mockito.Mockito.mock(Mockito.java:1908)
...
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in sun.misc.CompoundEnumeration@66c94af4
	at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:54)
	at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:57)
	at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:44)
	at org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:22)
	at org.mockito.internal.configuration.plugins.Plugins.<clinit>(Plugins.java:19)
	at org.mockito.internal.util.MockUtil.<clinit>(MockUtil.java:24)
	... 30 more
Caused by: java.lang.NullPointerException
	at org.mockito.internal.configuration.plugins.Plugins.getMockitoLogger(Plugins.java:66)
	at org.mockito.android.internal.creation.AndroidByteBuddyMockMaker.<init>(AndroidByteBuddyMockMaker.java:24)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at java.lang.Class.newInstance(Class.java:442)
	at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:49)
	... 35 more

I need to mock objects in my Instrumentation Tests also, so I need this dependency.

What can I do?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
TimvdLippecommented, Dec 2, 2020

Closing per the above comment.

0reactions
TimvdLippecommented, Sep 13, 2020

Thanks for filing the issue. Could you please provide us a minimal reproduction case that we can clone/download to debug the issue? Thanks in advance!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Studio (Gradle) cannot find Mockito - Stack Overflow
Try replacing testCompile with androidTestCompile , it works for me when importing Mockito libs. ... Unfortunatly, it didn't help. Same error keeps popping...
Read more >
Known issues with Android Studio and Android Gradle Plugin
To fix the issue for the current project, click Run > Edit Configurations and change the default JUnit configuration to only include the...
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 >
Android Studio is reporting Unresolved reference, in wrong ...
It seems, that Android Studio is mixing InstrumentationTest and UnitTest dependencies and gives this error. So many lines are highlighted RED, but all...
Read more >
Mockito framework site
A landing page for information about Mockito framework, a mocking framework for unit tests written in Java.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found