我有这个测试
@Test
public void theTimeViewMustBeDisplayedAfterRecordButtonClick(){
onView(withId(R.id.btn_record)).perform(click());
onView(withId(R.id.tempo)).check(matches(isDisplayed()));
}
但我的R.id.btn_record
有这个 OnTouchListener
public View.OnTouchListener getOnTouchListener(){
return new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
status.setText(R.string.record_status_message);
status.setTextColor(Color.BLUE);
tempo.setAnimation(getPulse());
presenter.startRecord(getActivity().getFilesDir().getPath(), UUID.randomUUID().toString());
return true;
case MotionEvent.ACTION_UP:
status.setText(R.string.default_status_message);
status.setTextColor(Color.BLACK);
tempo.clearAnimation();
presenter.stopRecord();
return true;
}
return false;
}
};
}
当 A 运行我的测试时,此测试锁定在此行
onView(withId(R.id.btn_record)).perform(click());
并且没有任何反应,但是如果删除了 OnTouchListener,测试将正常运行,为什么?知道吗?
完整代码:https://github.com/faeldix/faeldix-android-microphone-mvp
使用 UiController 的 MotionEvent 可能可以解决这个问题,请参见此处