has anyone seen issues with debugging tests becaus...
# mockk
n
has anyone seen issues with debugging tests because of this error:
Copy code
class redefinition failed: attempted to change the schema (add/remove fields)
java.lang.UnsupportedOperationException: class redefinition failed: attempted to change the schema (add/remove fields)
	at java.instrument/sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
	at java.instrument/sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:169)
	at io.mockk.proxy.jvm.transformation.JvmInlineInstrumentation.retransform(JvmInlineInstrumentation.kt:28)
	at io.mockk.proxy.common.transformation.RetransformInlineInstrumentation$doCancel$1.invoke(RetransformInlineInstrumentation.kt:38)
	at io.mockk.proxy.common.transformation.RetransformInlineInstrumentation$doCancel$1.invoke(RetransformInlineInstrumentation.kt:32)
	at io.mockk.proxy.common.transformation.ClassTransformationSpecMap.applyTransformation(ClassTransformationSpecMap.kt:41)
	at io.mockk.proxy.common.transformation.RetransformInlineInstrumentation.doCancel(RetransformInlineInstrumentation.kt:32)
	at io.mockk.proxy.common.transformation.RetransformInlineInstrumentation.access$doCancel(RetransformInlineInstrumentation.kt:6)
	at io.mockk.proxy.common.transformation.RetransformInlineInstrumentation$execute$1$1.invoke(RetransformInlineInstrumentation.kt:17)
	at io.mockk.proxy.common.transformation.RetransformInlineInstrumentation$execute$1$1.invoke(RetransformInlineInstrumentation.kt:17)
	at io.mockk.proxy.common.transformation.RetransformInlineInstrumentation.execute(RetransformInlineInstrumentation.kt:23)
	at io.mockk.proxy.common.ProxyMaker.inline(ProxyMaker.kt:104)
	at io.mockk.proxy.common.ProxyMaker.proxy(ProxyMaker.kt:48)
	at io.mockk.impl.instantiation.JvmMockFactory.newProxy(JvmMockFactory.kt:34)
	at io.mockk.impl.instantiation.AbstractMockFactory.newProxy$default(AbstractMockFactory.kt:24)
	at io.mockk.impl.instantiation.AbstractMockFactory.mockk(AbstractMockFactory.kt:59)
this reproduces on version 1.13.5 with the following:
Copy code
interface Foo {
    fun blah(value: Int): Int
}

@Test fun foo () {
    mockk<Foo>().apply {
        every { this@apply.blah(any()) } returns 10
    }

    mockk<(Int) -> Int>().also {  // <----------- Caused by lambda mock
        every { it(any()) } returns 10
    }
}
j
I’m curious about the rationale for using
.also
or
.apply
at all, while you can do
Copy code
val f: (Int) -> Int = mockk {
  every { this@mockk(any()) } returns 10
}
but anyway, following:
Copy code
class Aaaa {
    @Test
    fun aaa() {
        val g = mockk<(Int) -> Int>().also {  // <----------- Caused by lambda mock
            every { it(any()) } returns 10
        }
        expectThat(g(1)).isEqualTo(10)
    }
}
works without exceptions for me. (mockk 1.13.5, kotlin 1.9, junit 5.10, jvm 17) if this helps you
182 Views