Skip to content

Instantly share code, notes, and snippets.

@palfrey
Created December 31, 2010 15:45
Show Gist options
  • Select an option

  • Save palfrey/761092 to your computer and use it in GitHub Desktop.

Select an option

Save palfrey/761092 to your computer and use it in GitHub Desktop.
Robolectric test
@RunWith(RobolectricTestRunner.class)
public class MyActivityTest {
private Activity activity;
private Button pressMeButton;
private TextView results;
@Before
public void setUp() throws Exception {
activity = new MyActivity();
activity.onCreate(null);
pressMeButton = (Button) activity.findViewById(R.id.press_me_button);
results = (TextView) activity.findViewById(R.id.results_text_view);
}
@Test
public void shouldUpdateResultsWhenButtonIsClicked() throws Exception {
pressMeButton.performClick();
String resultsText = results.getText().toString();
assertEquals("Testing Android Rocks!", resultsText);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment