I have a private variable of another class which i...
# mockk
a
I have a private variable of another class which is declared and initialised inside my class. this variable calls its class functions inside my current class functions internally. how to test this using MockK in kotlin? Since for testing , i require to mock this variable but it is private.
k
From a purist point of view, if you have a private variable in your class, that's implementation detail that you shouldn't try to mock. If you want to mock it, then it should be an external dependency that's injected preferably through a constructor. Having said that, there may be tricks available (probably using reflection) that can achieve exactly what you're after, but I wouldn't recommend that.
a
Cool. Thanks Klitos. I would then make changes to my implementation.