Can't Instantiate Proxy for Class with Method Using NonEmptySet as a Parameter
mockk version: 1.13.17 kotest version : "5.9.1" kotlin version "2.0.21" arrow version "1.2.4"
Current Behavior
When using mockk , when mocked interface having method with NonEmptySet(arrow.core) as parameter, it errors Can't instantiate proxy for ... error
Test Class
import arrow.core.NonEmptySet
import arrow.core.nonEmptySetOf
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.mockk.coEvery
import io.mockk.mockk
class MockkBugTest: FunSpec(){
init {
test("should run") {
val someService = mockk<SomeInterface>(){
coEvery { someFunction(any()) } returns "abc"
}
val caller = SomeCaller(someService)
caller.callSomeFunction(nonEmptySetOf("a", "b", "c")) shouldBe "abc"
}
}
}
class SomeCaller(val someInterface: SomeInterface){
fun callSomeFunction(sets: NonEmptySet<String>){
someInterface.someFunction(sets)
}
}
interface SomeInterface {
fun someFunction(something: NonEmptySet<String>): String
}
class SomeClass : SomeInterface {
override fun someFunction(something: NonEmptySet<String>): String = something.reduce { acc, s -> acc + s }
}
Error
Can't instantiate proxy for SomeInterface
io.mockk.MockKException: Can't instantiate proxy for class SomeInterface
at io.mockk.impl.instantiation.JvmMockFactory.newProxy(JvmMockFactory.kt:64)
at io.mockk.impl.instantiation.AbstractMockFactory.newProxy$default(AbstractMockFactory.kt:24)
at io.mockk.impl.instantiation.AbstractMockFactory.mockk(AbstractMockFactory.kt:59)
We have the same issue. The issue appeared when updating the mokk version from 1.13.9 to 1.13.17.
I have the same problem after the update
val arrowVersion = "2.0.1"
val mockkVersion = "1.13.17"
With arrow, Nel (NonEmptyList)
same problem with version 1.14.2
spent some time to realize It was this type since the exception doesn't mention It.
Hi Isn't it because of type erasure and the inlining a value class?
@JvmInline
value class Box<T>(val items: List<T>)
interface SomeInterface {
val box: Box<String>
}
class MyTest {
@Test
fun myTest() {
val someService = mockk<SomeInterface>() // fails
}
}
I don't think it's doable.