How to test View in MVP implemented by Moxy?

I want to slip her Presenter'a mock instead, but I can not figure out how to do it? In View, my Presenter is created using @InjectPresenter .

  • Presenter is created elsewhere. The annotation simply indicates in which variable the link is placed. You can do the injection yourself. What modifier do you have for a variable? - Mikhail Vaysman
  • Variable without modifier (default). I can do something, but how can I cancel the injection that Moxy will do on her own? - tse
  • Why cancel? She inserts one option, and you replace it with a mock. - Mikhail Vaysman
  • Maybe I'm wrong, but it seems to me that the presenter who inserts the lib will immediately start to show something in the view, because the injection and the initialization will happen in onCreate (). I would therefore like to avoid such a scheme. - tse
  • one
    Inject presenter occurs in onCreate. But she attaches at the time of the call onStart / onResume. Therefore, after calling super.onCreate, you can substitute your presenter. Or you can make a method that will be annotated @ProvidePresenter ( github.com/Arello-Mobile/Moxy/wiki/… ) - senneco

1 answer 1

I must say that I am not an expert in Moxy. This answer is based on the source code of the library.

You can place a mock in the PresenterStore instead of the original object and then your mock will be inserted during the injection. You can get PresenterStore like this

 PresenterStore presenterStore = MvpFacade.getInstance().getPresenterStore(); 

And then using the add method add your mock .

  • one
    I would advise, in the case of mocking through the PresenterStore, in the PresenterStore, when you call get, return the required instance of Presenter - senneco