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?