Hi, I am getting following issue in unit testing w...
# android
a
Hi, I am getting following issue in unit testing with mokito
Copy code
java.lang.IllegalStateException: MyApplication.getInstance() must not be null
here is my function code snipped
Copy code
fun Favoritable.isFavorite() : Boolean {
   val user = MyApplication.getInstance().loginManager.loggedInUser
   return isFavorite(user)
}
stackoverflow 3
r
this static function is returning null as it says. check if you have mocked it properly.
k
Yup, what @ritesh said. You need to use mockStatic to mock the MyApplication class. When getInstance is called return a mocked MyApplication and so on.
a
Thanks, I got solution. I used mockk instead of mockito https://mockk.io/