I try to write some test in espresso for my android application, and I have a problem with Idle. If my isIdleNow() looks like this
public boolean isIdleNow() {
return true;
}
message is sent. But if IsIdleNow() must wait for some conditions (it doesn't return true at start) message isn't sent. My code
public class ImageViewIdlingResource implements IdlingResource {
private ImageView imageView=null;
ResourceCallback callback;
public ImageViewIdlingResource(ImageView imageView2){
this.imageView = imageView2;
}
@Override
public String getName() {
return "ImageViewIdlingResource";
}
@Override
public boolean isIdleNow() {
return !imageView.isShown();
}
@Override
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
this.callback = resourceCallback;
}}
and test
public class EspressoTest extends ActivityInstrumentationTestCase2<SplashScreen> {
public EspressoTest() {
super(SplashScreen.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
getActivity();
ImageViewIdlingResource imageResource = new ImageViewIdlingResource((ImageView)getActivity().findViewById(R.id.splashscreen_icon));
Espresso.registerIdlingResources(imageResource);
}
public void testListGoesOverTheFold() throws InterruptedException {
onView(withId(R.id.button)).check(matches(isDisplayed()));
}}
Aucun commentaire:
Enregistrer un commentaire