I want to use idling resources because I´m using RxJava and EventBus in my app and sometimes my tests fail (I´m thinking that is because that synchronisation).
Dependencies:
androidTestCompile 'com.android.support.test:runner:0.4'
androidTestCompile 'com.android.support.test:rules:0.4'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'recyclerview-v7'
}
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.squareup.retrofit:retrofit-mock:1.9.0'
androidTestCompile 'com.squareup.assertj:assertj-android:1.1.0'
androidTestCompile 'com.squareup.spoon:spoon-client:1.2.0'
Test failing:
@RunWith(AndroidJUnit4.class)
@SmallTest
public class PushNotificationTests {
@Test
public void testSomething(){
// do things...
MyIdlingResource eventBusIdlingResource = new MyIdlingResource();
registerIdlingResources(eventBusIdlingResource);
Order.Status status = Order.getCurrentObservable().toBlocking().first().getStatus();
assertThat(status).isEqualTo(Order.Status.PROGRESS); // Fail,
unregisterIdlingResources(eventBusIdlingResource)
}
}
Try but not working:
@RunWith(AndroidJUnit4.class)
@SmallTest
public class PushNotificationTests {
@Test
public void testSomething(){
// do things...
MyIdlingResource eventBusIdlingResource = new MyIdlingResource();
registerIdlingResources(eventBusIdlingResource);
// Wait manually?
int sleeps = 0;
while(!eventBusIdlingResource.isIdleNow() || sleeps < 10){
sleep(100);
sleeps++;
}
Order.Status status = Order.getCurrentObservable().toBlocking().first().getStatus();
assertThat(status).isEqualTo(Order.Status.PROGRESS); // Fail,
unregisterIdlingResources(eventBusIdlingResource)
}
}