I have an activity that uses RxLoader to retrieve data from the server when creating an activity and populate the list view. I also have test code that tries to click on the first line of the list after filling it.
Since I use RxLoader, I need to write a customized IdlingResource for Espresso. However, the problem is that the test ends (fails) before my list is full.
Here is my activity code:
RxLoaderManager.get(this).create( "my_loader", mRestService.loadData(), new RxLoaderObserver<MyData>() { @Override public void onNext(MyData data) {
Here is my implementation of IdlingResource:
public class IdlingApiServiceWrapper implements IdlingResource { public Observable<MyData> loadData(){ counter.incrementAndGet(); Observable<MyData> observable = api.loadData().finallyDo(new Action0() { @Override public void call() { counter.decrementAndGet(); notifyIdle(); } }); return observable;
}}
The problem is that: When I run the test code, the method "counter.decrementAndGet ()" is always called before the "onNext ()" method in my activity. My test fails because it expects the list to be populated.
Apparently I'm doing something wrong. But what am I doing wrong?
UPDATE:
Here is a snippet of clean code to illustrate the problem:
RxLoaderManager.get(this).create( "my_loader", myObservable.finallyDo(new Action0() { @Override public void call() {
In the above code, a piece of code inside finallyDo () is called before invoking the "onNext ()" of the observer. Should Do () finally be called after "onNext ()"?
android rx-java android-espresso
Hua H.
source share