Mockmaker 异常 - 无法初始化内联 Byte Buddy 模拟制作者

问题描述 投票:0回答:2

我的项目使用以下mockito依赖项。仅当我添加公司的内部依赖项时,我才面临以下问题。如何修复它?我已经尝试确保我的 Intellij dea 使用 JDK 而不是 JRE,如其他答案所建议的那样。

<dependency>

    <groupId>org.mockito</groupId>
    <artifactId>mockito-inline</artifactId>
    <version>3.12.4</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-junit-jupiter</artifactId>
    <scope>test</scope>
</dependency>
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               : 1.8
    JVM vendor name    : Azul Systems, Inc.
    JVM vendor version : 25.232-b18
    JVM name           : OpenJDK 64-Bit Server VM
    JVM version        : 1.8.0_232-b18
    JVM info           : mixed mode
    OS name            : Mac OS X
    OS version         : 10.16
        at org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker.<init>(InlineDelegateByteBuddyMockMaker.java:246)
        at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.<init>(InlineByteBuddyMockMaker.java:25)
        ... 73 more
    Caused by: java.lang.IllegalStateException: Error during attachment using: net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@d70f722
        at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:638)
        at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:611)
        at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:563)
        at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:540)
        at org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker.<clinit>(InlineDelegateByteBuddyMockMaker.java:117)
        ... 74 more
    Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at net.bytebuddy.agent.Attacher.install(Attacher.java:102)
        at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:633)
        ... 78 more
    Caused by: com.sun.tools.attach.AttachNotSupportedException: no providers installed
        at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208)
        ... 84 more
    [ERROR] testGenerateConnectLiteUrlServerError  Time elapsed: 0 s  <<< ERROR!
    java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
java spring-boot mockito illegalstateexception byte-buddy
2个回答
0
投票

异常表明:您的虚拟机不支持附加机制。您可以添加 JNA 作为测试依赖项,以允许 Byte Buddy 模拟它。


0
投票

您必须激活您的 jdk 附件设置。这仅适用于您的测试步骤:https://docs.gradle.org/current/userguide/build_lifecycle.html

对于 Gradle

test {
    jvmArgs '-Djdk.attach.allowAttachSelf=true'
}

对于带有 Surefire 的 Maven:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>3.1.2</version>
     <configuration>
       <argLine>-Djdk.attach.allowAttachSelf=true </argLine>
     </configuration>
</plugin>
© www.soinside.com 2019 - 2024. All rights reserved.