I use MVVM architecture and Dagger 2 in my application. I have a repository that gets data from servers, and when the data is retrieved ViewModel notifies the LiveData observer, which invokes the updateUI()
method from my Activity.
So, when I am testing which views are visible with espresso, I want to wait until the updateUI()
gets called. I cannot mock the ViewModel easily since I am using Dagger 2 but aside from that since it is an integration test, I don't want to do it in the first place.
Thread.sleep()
would be an awful and naive solution for this, since too little waiting time would cause the test to fail, too much of it would cause to the loss of valuable time and it also depends on the testing and network environment!
So what do we do here, what's the optimal solution to this problem?
Aucun commentaire:
Enregistrer un commentaire