Test DatePickerDialog with robolectric

111 views
Skip to first unread message

Łukasz Bandzarewicz

unread,
May 20, 2013, 11:11:59 AM5/20/13
to robol...@googlegroups.com
Original question can be found on http://stackoverflow.com/questions/16652414/test-datepickerdialog-with-robolectric

I'm trying to write simple test for the DatePickerDialog:

@Test
public void shouldSetStartedOnDate() {
  activity.findViewById(R.id.cruise_form_pick_started_on_button).performClick();

  DatePickerDialog dialog = (DatePickerDialog) ShadowDatePickerDialog.getLatestDialog();
  assertThat(dialog.isShowing(), is(true));
  dialog.updateDate(2013, 3, 13);

  ShadowDialog shadowDialog = Robolectric.shadowOf(dialog);
  shadowDialog.clickOnText("Done");
  assertThat(dialog.isShowing(), is(false));

  TextView startedOnText = (TextView) activity.findViewById(R.id.cruise_form_started_on);
  assertThat(startedOnText.getText().toString(), equalTo("2013-03-13"));
}

Unfortunately during test execution dialog.updateDate(2013, 3, 13); raises null pointer exception.
In the debugger I noticed that dialog.mDatePicker instance variable is null.

How to test this dialog with robolectric? 
Where can I find good examples for date pickers?

Emanuele Ianni

unread,
Nov 5, 2013, 9:04:52 AM11/5/13
to robol...@googlegroups.com
I'm also having the same problem, as posted here: https://groups.google.com/forum/#!topic/robolectric/2pV0qFQcZZw

Daniel x

unread,
Mar 3, 2014, 8:29:35 PM3/3/14
to robol...@googlegroups.com
Same problem here.

Has anybody got an update for us please? Thanks
Reply all
Reply to author
Forward
0 new messages