Could not initialize inline Byte Buddy mock maker. Problem when use mockito inline

3.1k Views Asked by At

I have a problem when active mockito inline. The test works perfectly in normal mode. The error is:

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 25.556 s <<< FAILURE! - in es.ddmain.utils.FileSystemUtilsTest
[ERROR] testIntentarSubirImagenYtestBorrarFichero  Time elapsed: 25.548 s  <<< ERROR!
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
        at es.ddmain.utils.FileSystemUtilsTest.testIntentarSubirImagenYtestBorrarFichero(FileSystemUtilsTest.java:61)
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in java.lang.CompoundEnumeration@249676e4
        at es.ddmain.utils.FileSystemUtilsTest.testIntentarSubirImagenYtestBorrarFichero(FileSystemUtilsTest.java:61)
Caused by: java.lang.reflect.InvocationTargetException
        at es.ddmain.utils.FileSystemUtilsTest.testIntentarSubirImagenYtestBorrarFichero(FileSystemUtilsTest.java:61)
Caused by: org.mockito.exceptions.base.MockitoInitializationException:

Could not initialize inline Byte Buddy mock maker.

It appears as if your JDK does not supply a working agent attachment mechanism.
Java               : 11
JVM vendor name    : Oracle Corporation
JVM vendor version : 11.0.2+9-LTS
JVM name           : Java HotSpot(TM) 64-Bit Server VM
JVM version        : 11.0.2+9-LTS
JVM info           : mixed mode
OS name            : Windows 7
OS version         : 6.1

        at es.ddmain.utils.FileSystemUtilsTest.testIntentarSubirImagenYtestBorrarFichero(FileSystemUtilsTest.java:61)
Caused by: java.lang.IllegalStateException: Could not self-attach to current VM using external process
        at es.ddmain.utils.FileSystemUtilsTest.testIntentarSubirImagenYtestBorrarFichero(FileSystemUtilsTest.java:61)

[EDIT] Sorry, i forgot to include version of mockito.

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-junit-jupiter</artifactId>
    <version>4.8.1</version>
    <scope>test</scope>
</dependency>

what can i do to fix this? I'm noob in mockito

Thanks

1

There are 1 best solutions below

2
On BEST ANSWER

Most likely you ran across Could not self-attach to current VM using external process (ByteBuddyAgent.installExtension) #2741

Mockito is known not to be able to mock a few classes it uses in its internals. The issue is closed as infeasable

Unfortunately, InputStream is one of the classes that Mockito relies on internally for its behavior. Stubbing InputStream will therefore lead to undefined behavior. Additionally, it is advised not to mock classes you don't own: https://github.com/mockito/mockito/wiki/How-to-write-good-tests#dont-mock-a-type-you-dont-own We are working on improving the user experience by working on a DoNotMock feature to avoid mocking classes/methods that are known to crash Mockito internals (#1833). Therefore, I am closing this as "Infeasible". Apologies for the uninformative exception that is thrown.