sockeqwe / mosby

A Model-View-Presenter / Model-View-Intent library for modern Android apps
http://hannesdorfmann.com/mosby/
Apache License 2.0
5.49k stars 841 forks source link

Testing a MvpLceRxPresenter using sample MvpLceRxPresenterTest is failing #110

Closed jjvargas closed 8 years ago

jjvargas commented 8 years ago

Not sure if the question belongs to this repo but I am using this classes to try to test a enter that extends from MvpLceRxPresenter and using the TestPresenter as sample

https://github.com/sockeqwe/hdlib/tree/master/mosby-rx/src/test/java/com/hannesdorfmann/hdlib/mosby/rx/lce

But when I run the test I get .

So the test is running but its not passing, not sure If this classes meant to be working ? Cheers

Wanted but not invoked: testView.showContent(); -> at com.hannesdorfmann.mosby.testing.presenter.MvpLcePresenterTest.startLceTests(MvpLcePresenterTest.java:80)

However, there were other interactions with this mock: testView.showLoading(false); -> at com.hannesdorfmann.mosby.sample.dagger2.repos.MvpLceRxPresenter.subscribe(MvpLceRxPresenter.java:63)

Wanted but not invoked: testView.showContent(); -> at com.hannesdorfmann.mosby.testing.presenter.MvpLcePresenterTest.startLceTests(MvpLcePresenterTest.java:80)

However, there were other interactions with this mock: testView.showLoading(false); -> at com.hannesdorfmann.mosby.sample.dagger2.repos.MvpLceRxPresenter.subscribe(MvpLceRxPresenter.java:63)

at com.hannesdorfmann.mosby.testing.presenter.MvpLcePresenterTest.startLceTests(MvpLcePresenterTest.java:80)
at com.hannesdorfmann.mosby.testing.presenter.MvpLceRxPresenterTest.testPresenter(MvpLceRxPresenterTest.java:43)
sockeqwe commented 8 years ago

Actually this test class is part of this repo, so your question belongs here:

https://github.com/sockeqwe/mosby/blob/master/testing/src/main/java/com/hannesdorfmann/mosby/testing/presenter/MvpLcePresenterTest.java

Maybe this is duplicated #68 (scroll down, someone else joined the conversation with similar question, but the original question was an entirely different one). Maybe, you will find the answer right there. Otherwise, I will try to help you.

jjvargas commented 8 years ago

Thanks for the response. I ended up using a presenter LceRetrofitPresenter and to test it the LceRetrofitPresenterTest.java file that you have provided. it all works fine to test the presenter.

Now to test the Model on the Dagger2 Mosby sample, which according to #68 , Its the business logic so I can test that loading data over https works and gets parsed correctly.

public interface GithubApi
{
    @GET("/repositories")
    @Headers("Cache-Control: no-cache")
    public void getRepos(Callback<List<Repo>> callback);
}

I have found some articles, check your sample on the mail app and also opened a question in SO http://stackoverflow.com/questions/35003794/how-to-test-a-rest-api-that-uses-retrofit-and-dagger2/35004089#35004089

Its still not very clear to me, what I want is to test the mode using real network and not a mocked response. Any input on this?

And for the View , you mentioned in the past to use MvpLceFragmentTest and MvpLceActivityTest to test your MvpLceFragment / Activity. I cant find these classes do you have any sample? Thanks

sockeqwe commented 8 years ago

Hi, I have answered you on Stackoverflow.

Regarding testing View: MvpLceFragmentTest have been removed from this repo. But the only thing they have tested is that a view with id R.id.loadingView has been displayed by doing something like assertEquals(View.VISIBLE, loadingView.getVisibility(), same for errorView and contentView. But those kind of things are already tested internally by mosby if you use MvpLceFragment or MvpLceActivity as long as you don't manipulate contentView, errorView, loadingView somewhere by your own.