Junit测试列表视图拖放

时间:2014-01-16 06:07:36

标签: android listview android-listview junit

如何使用Android自定义列表视图拖放进行Junit测试。我使用beaurca拖动排序库为我的自定义列表视图,它的工作正常。我已经使用JUnit测试了onitem click并且想要测试拖动排序功能,但是无法执行此操作。以前是否有人在listview上执行了拖拽排序的测试用例,请帮助我。

以下是我的问题的快照,

    protected void setUp() throws Exception {
    super.setUp();
    solo = new Solo(getInstrumentation(), getActivity());
    setActivityInitialTouchMode(false);
    getListActivity = getActivity();
    dragSortListView = (DragSortListView) atosListActivity
            .findViewById(com.as.listreq.R.id.item_list);
    listAdapter = dragSortListView.getAdapter();
}

public void testEntryConditions() {

    sleep(SLEEP_TIME);
    assertTrue(dragSortListView.getOnItemClickListener() != null);
    assertTrue(listAdapter != null);
    assertEquals(listAdapter.getCount(), ADAPTER_COUNT);        
    sleep(SLEEP_TIME);
}


public void testDragAndDrop() { //not completed 

    sleep(SLEEP_TIME);
    downTime = SystemClock.uptimeMillis();
    // event time MUST be retrieved only by this way!
    eventTime = SystemClock.uptimeMillis();
    Instrumentation inst = getInstrumentation();    
    getListActivity .runOnUiThread(new Runnable() {
        public void run() {

            View listItemView = null;                               
            listItemView = dragSortListView.getAdapter().getView(2, null, dragSortListView);
            MotionEvent event1 = MotionEvent.obtain(downTime, eventTime,
                    MotionEvent.ACTION_DOWN, 200, 200, 0);
            // MotionEvent e1 = null;               
            DragSortController dsc = new DragSortController(dragSortListView);
            dsc.onCreateFloatView(2);
            dsc.startDrag(2, 200, 200);
            dsc.onTouch(listItemView, event1);
        }
    });     
    sleep(SLEEP_TIME);          
}

0 个答案:

没有答案