lundi 18 décembre 2017

How to mock getApplication() for a unit test

I have a unit test where I'm trying to test my model's logic. In the test I have:

loginViewModel = new LoginViewModel();

The LoginViewModel class has an init method that has the following line of code:

MyApplication.getApplication().component.inject(this)

The problem is that when I try to test, it crashes and says:

MyApplication.getApplication() must not be null

What do I need to do to mock this object so that I can return a valid MyApplication instance so that the test can run?

Aucun commentaire:

Enregistrer un commentaire