Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kurthaeusler
Created July 9, 2012 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurthaeusler/3076103 to your computer and use it in GitHub Desktop.
Save kurthaeusler/3076103 to your computer and use it in GitHub Desktop.
public class ActivityOneTest extends
android.test.ActivityInstrumentationTestCase2<ActivityOne> {
private ActivityOne thisActivity;
private Button bStartActivityTwo;
public ActivityOneTest() {
super("com.rocketeercoders.wotonio.ActivityOne", ActivityOne.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
thisActivity = getActivity();
bStartActivityTwo = (Button) thisActivity
.findViewById(com.rocketeercoders.wotonio.R.id.bStartActivityTwo);
}
@UiThreadTest
public void testHaveADrinkButtonPush() {
bStartActivityTwo.performClick();
ActivityManager am = (ActivityManager) thisActivity
.getSystemService(Service.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> processes = am.getRunningTasks(1);
assertEquals(ActivityTwo.class.getName(),
processes.get(0).topActivity.getClassName());
// This works, but leaves Activity2 in the foreground, and prevents the other tests from running.
// What I need is something like
// ActivityTwo activityTwo = ?
// activityTwo.finish();
}
@UiThreadTest
public void anotherTest() {
// If the other test runs first, this test just freezes cos ActivityTwo is in the foreground.
// Actual test skipped...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment