introduce a BaseIntegration with SpooningFailureHandler

This commit is contained in:
ligi 2014-06-05 22:26:01 +02:00
parent 4a9ee42a3c
commit f5a390f851
3 changed files with 55 additions and 2 deletions

View file

@ -0,0 +1,23 @@
package org.ligi.passandroid;
import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import org.ligi.passandroid.reporting.SpooningFailureHandler;
import static com.google.android.apps.common.testing.ui.espresso.Espresso.setFailureHandler;
public abstract class BaseIntegration<T extends Activity> extends ActivityInstrumentationTestCase2<T> {
public BaseIntegration(Class<T> activityClass) {
super(activityClass);
}
@Override
public void setUp() throws Exception {
super.setUp();
setFailureHandler(new SpooningFailureHandler(getInstrumentation().getTargetContext()));
}
}

View file

@ -1,6 +1,5 @@
package org.ligi.passandroid;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.MediumTest;
import com.squareup.spoon.Spoon;
@ -17,7 +16,7 @@ import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewA
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
public class TheEmptyTicketList extends ActivityInstrumentationTestCase2<TicketListActivity> {
public class TheEmptyTicketList extends BaseIntegration<TicketListActivity> {
public TheEmptyTicketList() {
super(TicketListActivity.class);

View file

@ -0,0 +1,31 @@
package org.ligi.passandroid.reporting;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import com.google.android.apps.common.testing.ui.espresso.FailureHandler;
import com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler;
import com.squareup.spoon.Spoon;
import org.hamcrest.Matcher;
public class SpooningFailureHandler implements FailureHandler {
private final FailureHandler delegate;
private final Context context;
public SpooningFailureHandler(Context targetContext) {
delegate = new DefaultFailureHandler(targetContext);
context = targetContext;
}
@Override
public void handle(Throwable error, Matcher<View> viewMatcher) {
delegate.handle(error, viewMatcher);
if (context instanceof Activity) {
Spoon.screenshot((Activity) context, "error");
}
}
}