My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping

Monday, November 30, 2020

Mockito MockMaker Java IllegalStateException Error: How to Fix Mockito Plugin error in Testing

 There are times when you will land into problems while running Mock tests using Mockito. A Sample error could be like:

java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker

The issue is that the Mockito core depends on a library called byte-buddy and this problem is mostly occurred when mockito doesn’t find a matching byte buddy jar version.

Error screenshot:

To Solve this issue find out the mockito core version your project is using.

In eclipse, you can check in project build path by navigating as follows:

Right click on project -> Properties -> Java build path -> Libraries tab

For IntelliJ This could be different. Look the screenshot below:

Search maven repository for that version of mockito core. To me, it was :

Description of issue:

The actual issue it seems is because of error from ByteBuddyAgent. I found following stacktraces that pointed me to the error:

Caused by: java.lang.IllegalStateException: Error during attachment using: net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@e32787d

at net.bytebuddy.agent.ByteBuddyAgent.install(

at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.<clinit>(

... 34 more

Caused by: java.lang.reflect.InvocationTargetException

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(

at net.bytebuddy.agent.ByteBuddyAgent.install(

Solution to fix the error:

Look at the Compile Dependencies section. Note down the correct dependent version of byte-buddy and include in the project. If the jar is already included with some other version, override the version with this correct version.

Also, i did see following in stacktrace:

[ERROR] error: error while loading Object, Missing dependency 'object scala in compiler mirror', required by /modules/java.base/java/lang/Object.class

So, fix above two issues. Build the application and run the tests again. Your issue related to MockMaker must be solved by now.

Voila :)


No comments:

Post a Comment