I am writing an Android JUnit test that iterates through a list of MotionEvents and dispatches them to the Activity under test. For most events, I can just use the activity.dispatchTouchEvent(MotionEvent) method. For dialogs, I have to obtain the dialog in memory and call the dispatchTouchEvent directly. I am having trouble with android.widget.Spinner objects. The dispatchTouchEvent method seems to getting ignored.
For example, a Spinner (Mode = DIALOG) appears on the screen, the test code is dispatching a MotionEvent with the proper (x, y) coordinates and actions (ACTION_DOWN followed by ACTION_UP):
Spinner spinner = (Spinner) activity.findViewById(R.id.spinnerId);
spinner.dispatchTouchEvent(motionEvent); //returns true, but Spinner has not been touched
View v = spinner.getChildAt(0);
v.dispatchTouchEvent(motionEvent); //returns false, Spinner has not been touched
For now, I'm using Robotium to directly click the Spinner, but this is not desired for long term. Any suggestions?