Tag: robolectric

  • Robolectric reference

    Robolectric Android testing Fragments and more private ReminderManagerFragment startReminderManagerFragment() { final ReminderManagerFragment fragment = new ReminderManagerFragment(); SupportFragmentTestUtil.startVisibleFragment(fragment); return fragment; } @Test public void reminderManagerTest() throws Exception { // by default there should be 3 Reminder rows ReminderManagerFragment fragment = startReminderManagerFragment(); assertThat(fragment).isNotNull(); Button addButton = (Button) fragment.getView().findViewById(R.id.reminder_add_button); assertThat(addButton).isNotNull(); List<Reminder> reminders = getReminders(TestValues.BillyUser); assertThat(reminders.size()).isEqualTo(3); // add a…

  • Android Robolectric Support Fragment FragmentTestUtil

    To use Android Support Fragment v4 in Robolectric 3.0 you must add gradle dependency in /app/build.gradle testCompile ‘org.robolectric:shadows-support-v4:3.0’ Then import into your Robolectric testing java class import org.robolectric.shadows.support.v4.SupportFragmentTestUtil; then you can create/start android support v4 fragments within your Robolectric testing java class for unit testing: SupportFragmentTestUtil.startVisibleFragment(fragment); Cross posted to StackOverflow Android Robolectric Support Fragment.