Android 自動化測試

來源:互聯網
上載者:User

一、基本概念

自動化測試就是類比人工測試,例如點擊按鈕,下滑,點擊Menu,退出,這一系列的動作都由代碼實現。這樣的優點主要是可以反覆執行很多次,來觀察程式是否出現異常。


二、開源架構

主要是robotium,網站是http://code.google.com/p/robotium/

中文網站http://www.robotium.cn/


三、搭建測試環境,並運行第一個自動化測試代碼流程,參考:

http://www.robotium.cn/archives/210


四、模仿上下左右滑動,參考

http://blog.softteco.com/2011/02/touch-hold-swipe-release-gesture.html


五、類比下滑,代碼:

private void scrollDown() {Instrumentation inst = getInstrumentation();long downTime = SystemClock.uptimeMillis();// event time MUST be retrieved only by this way!long eventTime = SystemClock.uptimeMillis();// Just init your variables, or create your own coords logic :)float xStart = 200;float yStart = 900;// simulating thick finger touchfloat x0 = 200;float y0 = 900;float x9 = 200;float y9 = 100;// release finger, logically to use coords from last moventfloat x10 =200;float y10 = 100;try {// sending event - finger touched the screenMotionEvent event = MotionEvent.obtain(downTime, eventTime,MotionEvent.ACTION_DOWN, xStart, yStart, 0);inst.sendPointerSync(event);// sending events - finger is moving over the screeneventTime = SystemClock.uptimeMillis();event = MotionEvent.obtain(downTime, eventTime,MotionEvent.ACTION_MOVE, x0, y0, 0);inst.sendPointerSync(event);event = MotionEvent.obtain(downTime, eventTime,MotionEvent.ACTION_MOVE, x9, y9, 0);inst.sendPointerSync(event);// release finger, gesture is finishedevent = MotionEvent.obtain(downTime, eventTime,MotionEvent.ACTION_UP, x10, y10, 0);inst.sendPointerSync(event);} catch (Exception ignored) {//Log.d("gcy111", "run");}}




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.