2013-03-13 53 views
0

我写一个Android JUnit测试,通过MotionEvents列表进行迭代,并且分派他们到活动测试。对于大多数事件,我只能使用activity.dispatchTouchEvent(MotionEvent)方法。对于对话框,我必须获取内存中的对话框并直接调用dispatchTouchEvent。我遇到了android.widget.Spinner对象的问题。 dispatchTouchEvent方法似乎被忽略。的Android无法调度触摸事件,以微调

例如,微调(模式= DIALOG)出现在屏幕上时,测试码分派与适当的(X,Y)一个MotionEvent坐标和动作(ACTION_DOWN接着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 

现在,我使用Robotium直接单击微调,但不希望长期。有什么建议么?

+0

你为什么不使用spinner.performClick();而不是spinner.dispatchTouchEvent(motionEvent); ? – maszter 2013-03-13 16:42:31

+0

这样做是为了捕获所有的运动事件。 (例如ACTION_DOWN,ACTION_UP,ACTION_MOVE)。在做出选择之前,用户可能会滚动Spinner。 – diggybub 2013-03-14 19:11:41

回答

0

因此,也许你可以在活动水平通过为微调的情况下做中心调度事件作为X,Y(Robotium这样做,但通过仪器传递motionEvent而不是活动)。