https://kotlinlang.org logo
#android
Title
# android
n

Naveen

07/13/2022, 8:02 PM
Hi everyone. Does anybody have idea how to mock object classes in android?
t

Tower Guidev2

07/14/2022, 6:54 AM
if you mean mocking Kotlin objects for testing... https://mockk.io/
n

Naveen

07/14/2022, 7:00 AM
I mean mocking a singleton class which is defined like this :
Copy code
object Singleton{}
b

bezrukov

07/14/2022, 7:06 AM
didn't do that for a while, but most like powermock library still do that
t

Tgo1014

07/14/2022, 7:10 AM
n

Naveen

07/14/2022, 7:19 AM
@Tgo1014 Thanks a lot I'll try this. Also, is this not recommended to have singletons becuase they are hard to mock?
t

Tgo1014

07/14/2022, 7:22 AM
I don't think it's hard to mock. Anything has it uses you just need to see what works better for each situation.
n

Naveen

07/14/2022, 7:24 AM
Thanks. Got it
I'll try this Lib and will get back here
4 Views