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
ritesh
01/31/2019, 11:33 AM
this static function is returning null as it says. check if you have mocked it properly.
k
kd
01/31/2019, 2:51 PM
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
Animesh
02/01/2019, 9:05 AM
Thanks, I got solution. I used mockk instead of mockito https://mockk.io/