https://kotlinlang.org logo
#mockk
Title
# mockk
m

Michael de Kaste

04/14/2022, 2:57 PM
Hello, how do I effectively mockk a value class?
if I mockk a value class, I get
Copy code
io.mockk.MockKException: no answer found for: MyClass(#8).unbox-impl()
If I remove the whole value class aspect, my tests run and work
e

ephemient

04/14/2022, 2:58 PM
you can't (and like data classes, I don't think it generally makes sense to)
👍 2
m

Michael de Kaste

04/14/2022, 3:05 PM
follow up problem:
Copy code
sealed interface Sealed{
    @JvmInline value class MyClass(someOtherClassINeedToMockk: Any) : Sealed
}
gives me the following error:
Copy code
cannot cast 'the class I want to mockk' to 'Sealed'
when my code checks:
Copy code
val isTheClassIneed = sealed is MyClass
only in the mockk when the class is a value class
e

ephemient

04/14/2022, 3:09 PM
any type of upcast loses the value-ness of a value class so I'm not sure what you're trying to do there
210 Views