Spring Boot允许将一个接口(SomeComponent)的所有实现的列表作为List注入另一个组件(SomeOtherComponent),例如
@Component
interface SomeComponent
@Component
class SomeComponentImpl0 : SomeComponent
@Component
class SomeComponentImpl1 : SomeComponent
class SomeOtherComponent {
@Autowired
lateinit var impls: List<SomeCompo
我想模拟一个字符串扩展。
我已经阅读了应该如何做到这一点的说明,使用
mockStatic("kotlin.String")
或
mockkStatic("kotlin.kotlin_builtins")
但它一直在说
Caused by: io.mockk.MockKException: Can't instantiate proxy for class kotlin.String
at io.mockk.impl.instantiation.JvmMockFactory.newProxy(JvmMockFactory.kt:64)
at io.moc
我试图在shared项目的模块中编写测试。在共享模块的build.gradle.kts文件中,我有以下内容:
sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
//TOD
当我尝试在UI测试中使用MockK时,我遇到了一个错误,这个测试在Unittest中非常有效。
MockK could not self-attach a jvmti agent to the current VM
全错误报告
Caused by: io.mockk.proxy.MockKAgentException: MockK could not self-attach a jvmti agent to the current VM. This feature is required for inline mocking.
This error occured due to an I/O
我一步一步地遵循了许多博客的说明,用MockK实现了一个模拟:
class SWServiceImplTest {
@MockK
lateinit var externalApi: ExternalApiService
@InjectMockKs
lateinit var SWService: SWServiceImpl
@Before
fun setUp() = MockKAnnotations.init(this)
@Test
fun SWCharacterReturnsCorrectValues() {
我试图使用mockk框架模拟对hibernate的调用。我需要模拟这里返回的查询对象。当我使用下面的代码时,我会得到这个编译器错误,它不是kotlin开发人员,我不明白。
类型错配:推断类型是() ->查询,但是Query<(raw) Any!预期
var mockedQuery = mockk<Query<Any>>{ }
var mockSessionFactory = mockk<SessionFactory> {
every { openSession() } returns moc
使用mockk测试kotlin函数。
private val serviceObject = mockk<Service>()
private val serviceToBeTested = ServiceToBeTestd(Service)
fun test(){
when(serviceObject.function1(argument1,argument1))
.thenReturn(<something>)
}
当我尝试运行它时,我得到了这个错误:
io.mockk.MockKException: no answer f
我有个Kotlin多平台项目。我最近更新到Kotlin 1.4-M2 (我需要它来解决Ktor的一些问题)。在更新了所有所需的库、解决了所有的gradle问题并成功编译了我的Android项目之后,我现在在构建iOS应用程序时遇到了以下错误:
Task :shared:compileKotlinIosX64
e: Compilation failed: Could not find declaration for unbound symbol org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionPublicSymbolImpl@56f11f
我试图在Kotlin 1.4.10和@SpringBootTest (SpringBoot2.2.2.RELEASE)中使用MockK 1.10.2,但由于
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
2020-11-05 15:00:37.878 WARN --- [ main] i.m.p.j.t.InliningClassTransforme
我有以下测试 class MyTest{
private val s1= mockk<S1>()
private val s2= mockk<S2>()
private val s3= mockk<S3>()
private val requestHandler = RequestHandler(s1, s2, s3)
private val webTestClient = WebTestClient
.bindToRouterFunction(RouterConfiguration(reques