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

Michael de Kaste

05/13/2022, 9:10 AM
Can someone help me with the problem I keep facing with value classes? I have a simple class that holds multiple fields, but one of the is the "Duration" value class of kotlin. when I try to mockk it, (v1.12.2) I keep getting classcastexceptions from Long to Duration
Copy code
every { someClass.duration } returns 30.minutes
I can't run this
e

ephemient

05/13/2022, 11:08 AM
m

Michael de Kaste

05/13/2022, 11:31 AM
yeah I saw this as well. It is what it is, but now I literally have no idea how to properly test this 🤔
e

ephemient

05/13/2022, 1:29 PM
does
Copy code
every { someClass.duration as Any? }.returns(30.minutes as Any?)
work? (just a thought, there's a good chance that doesn't help) otherwise you'll just have to avoid mocking by using the real object or a writing a fake
23 Views