模拟奇怪的行为(不适用于 AnyNameTest 类)

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

在这样的测试中,它会因错误而中断

class MyTest {
    val m = mockk<MockedClass>()

    @Test
    fun test(){}
}
java.lang.ExceptionInInitializerError
Caused by: java.lang.IllegalStateException: Error during attachment using: net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@308a6984
Caused by: java.lang.reflect.InvocationTargetException
Caused by: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded

但是当我从类名中删除

Test
时它就起作用了。我应该担心吗?有办法解决这个问题吗?

我使用Java 8,Kotlin 1.9.22,Spring Boot 2.7.10和com.ninja-squad.springmockk 3.1.2(也尝试了io.mockk.mockk最后一个和1.9.3版本 - 同样的问题)((可能看起来像过度劳累,但经过很长时间才找到原因))

java spring kotlin mockk
1个回答
0
投票

这段代码

import io.mockk.mockk
import org.junit.jupiter.api.Test

class MyTest {
    val m = mockk<MockedClass>()

    @Test
    fun test(){}
}

class MockedClass {}

配合使用效果良好:

  • 科特林
    1.9.23
  • testImplementation("io.mockk:mockk")
    版本
    1.13.12
  • testImplementation("org.junit.jupiter:junit-jupiter-engine")
    版本
    5.10.3
© www.soinside.com 2019 - 2024. All rights reserved.