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

mkrussel

06/29/2021, 1:16 AM
I'm trying to mock private properties from in a companion object. When I run the tests they throw an exception.
io.mockk.MockKException: can't find property workerHandler for dynamic property get
m

Mattia Tommasone

06/29/2021, 8:23 AM
I think it may be an issue with the fact that the first argument for mockkObject is vararg, so if you call it the way you do the second parameter is part of the vararg
it should be working if you write it as
mockkObject(GeoJsonSource.Companion, recordPrivateCalls = true)
m

mkrussel

06/29/2021, 11:17 AM
When I switch to that I get
Missing mocked calls inside every { ... } block: make sure the object inside the block is a mock
which is what I got before adding the
true
argument.
So it is the mocking of the
mainHandler
that fails, The
workerHandler
passes. Looking at the decompiled code, the
mainHandler
is turned into a static field of the
GeoJsonSource
class and there is no getter in the
Companion
object.
464 Views