Closed hussam789 closed 7 years ago
HomeFeedInteractor
which handles all those intents and applies the stateReducer. Maybe we should refactor that.I understand, my question is could you provide an example for a unit test for the presenter in MVI sample app (currently there are no tests for it)? Or can you give us any advice for writing a test for MVI pattern in general?
Got it! Yes that is not documented at all. I apologise. I will write add some unit tests for the sample app and will beginn to write documentation / github pages for MVI and Testing.
Basically, to test a MVI presenter you have to do the following: 1) Create a View Instance i.e. by using Mockito 2) Instantiate your presenter 3) call presenter.attachView(yourMockedView). This calls internally presenter.bindIntents() 4) now your presenter is setup properly and bound to the view. Now you can invoke the intent you want to test. 5) invoking an intent will finally result in a view.render(model). Then you catch this model and test it like Assert.assertEquals(expectedModel, receivedModel)
hussam789 notifications@github.com schrieb am Do., 26. Jan. 2017, 22:35:
I understand, my question is could you provide an example for a unit test for the presenter in MVI sample app (currently there are no tests for it)? Or can you give us any advice for writing a test for MVI pattern in general?
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/sockeqwe/mosby/issues/197#issuecomment-275521236, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjnrthOoqvK0UWOBghXKDjkjZjUDdGvks5rWRGkgaJpZM4Luzh2 .
Full example can be found here: https://github.com/sockeqwe/mosby/blob/master/sample-mvi/src/test/java/com/hannesdorfmann/mosby3/sample/mvi/view/home/HomePresenterTest.java
Will also put more infos about testing in documentation
I was wondering if you want to build this sample using TDD, and probably start writing tests for MviPresenters, but currently
MviBasePresenter
hasbindIntents
function whichBut if you want to write to test the MviPresenter, you want to test each Intent function e.g (loadFirstPage, pullToRefresh...). based on MVI pattern, given
previousState
(ViewModel) the Presenter applies the Model function (for exampleloadFirstPage
) and uses StateReducer function to output anewState