If you are working on Play using sbt as a build tool, inteliJ at times may complain that the MockMaker plugin is not found when you run your tests by right clicking the test directory and invoking Run

You could verify the tests are running fine from the command line too, using the command

sbt test.

As a measure could run the command when the MockMaker plugin is not found in inteliJ, it may run or it may not run.

This usually happens when the Mockito framework is not able to find related dependencies as per the expected version.

Mockito core depends on a library called byte-buddy and this problem occurs when mockito is unable to find a matching byte-buddy jar version.

Error appears as follows

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) ~[mockito-core-2.23.4.jar:na]
    at com.sun.proxy.$Proxy61.getHandler(Unknown Source) ~[na:na]
    at org.mockito.internal.util. MockUtil.isMock(MockUtil.java:81) ~[mockito-core-2.23.4.jar:na]
    ...
    ...
Caused by: java.lang.NoClassDefFoundError: net/bytebuddy/dynamic/loading/ ClassInjector$UsingReflection
    at org.mockito.internal.creation.bytebuddy. SubclassInjectionLoader.<init>(SubclassInjectionLoader.java:28) ~[mockito-core-2.23.4.jar:na]
    at org.mockito.internal.creation.bytebuddy. SubclassByteBuddyMockMaker.<init>(SubclassByteBuddyMockMaker.java:33) ~[mockito-core-2.23.4.jar:na]
    at org.mockito.internal.creation.bytebuddy. ByteBuddyMockMaker.<init>(ByteBuddyMockMaker.java:21) ~[mockito-core-2.23.4.jar:na]
    
To solve this,
Find the version of mockito in the build.sbt file
"org.mockito" % "mockito-core" % "2.22.0" % "test",

Double check whether the library is referenced correctly in the project

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

Next look up the maven repository for the version and the corresponding dependencies version. https://mvnrepository.com/artifact/org.mockito/mockito-core/2.22.0

Scroll to the bottom to look up compile time dependencies for the mockito-core,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.

 

Leave a Reply

Your email address will not be published. Required fields are marked *