移動(dòng)APP測(cè)試之Monkey Test運(yùn)用

Monkey是Android平臺(tái)自動(dòng)化測(cè)試的一種手段,可以在模擬器里或?qū)嶋H設(shè)備中運(yùn)行,它向系統(tǒng)發(fā)送偽隨機(jī)的用戶事件流,如按鍵輸入、觸摸屏輸入、手勢(shì)輸入等,實(shí)現(xiàn)對(duì)正在開發(fā)的應(yīng)用程序進(jìn)行壓力測(cè)試。

當(dāng)然對(duì)于移動(dòng)APP測(cè)試,monkey測(cè)試出了壓力測(cè)試外,也可以做做簡(jiǎn)單的機(jī)型配適,就是測(cè)試App是否會(huì)出現(xiàn)crash等異常,以此來判讀其釋放與機(jī)型適配,可以發(fā)現(xiàn)程序無響應(yīng)問題和崩潰問題。

接下來簡(jiǎn)單說說:

Monkey程序由Android系統(tǒng)自帶,使用Java語言寫成,在Android文件系統(tǒng)中的存放路徑是:/system/framework/monkey.jar;

Monkey.jar程序是由一個(gè)名為“monkey”的Shell腳本來啟動(dòng)執(zhí)行,shell腳本在Android文件系統(tǒng)中的存放路徑是:/system/bin/monkey;

特征

1、測(cè)試的對(duì)象僅為應(yīng)用程序包,有一定的局限性。

2、Monky測(cè)試使用的事件流數(shù)據(jù)流是隨機(jī)的,不能進(jìn)行自定義。

3、可對(duì)MonkeyTest的對(duì)象,事件數(shù)量,類型,頻率等進(jìn)行設(shè)置。

這樣就可以通過在CMD窗口中執(zhí)行: adb shell monkey{+命令參數(shù)}來進(jìn)行Monkey測(cè)試了。

基本使用

1.進(jìn)入monkey

命令:adb shell/system/bin/monkey

2.運(yùn)行monkey

命令:adb shell monkey ,是指隨機(jī)發(fā)送事件數(shù)

adb shell monkey 100,運(yùn)行monkey并執(zhí)行了100件隨機(jī)事件。

3. monkey常規(guī)類命令

adb shell monkey -h顯示monkey參數(shù)幫助信息usage

adb shell monkey -v打印出日志信息,每個(gè)-v將增加反饋信息的級(jí)別,最多支持3個(gè)-v

4. monkey事件類命令

adb shell monkey -f

讓monkey運(yùn)行指定monkey腳本,為測(cè)試腳本名,是指循環(huán)次數(shù)。

adb shell monkey -s

可以重復(fù)之前的隨機(jī)操作,-s后接隨機(jī)數(shù)的生成器的seed值。

adb shell monkey --throttle

表示每個(gè)事件之間的固定延遲事件,時(shí)間的單位為ms,若后面不接時(shí)間,monkey將不會(huì)延遲

事件百分比

adb shell monkey --ptc-touch

設(shè)定觸摸事件的百分比

adb shell monkey --ptc-motion

設(shè)定動(dòng)作事件的百分比

adb shell monkey --ptc-trackball

設(shè)定軌跡球事件的百分比

adb shell monkey --ptc-nav 設(shè)定基本導(dǎo)航事件的百分比

adb shell monkey --ptc-majornav

設(shè)定主要導(dǎo)航事件的百分比

adb shell monkey --ptc-syskeys

設(shè)定按鍵事件的百分比

adb shell monkey --ptc-appswitch

設(shè)定啟動(dòng)事件的百分比

adb shell monkey --ptc-anyevent

其他類型事件的百分比,包括keypress、不常用button以及其他未提及事件

5. monkey約束類命令

adb shell monkey -p

,測(cè)試一個(gè)或多個(gè)包名,每個(gè)-p對(duì)應(yīng)一個(gè)包。

adb shell monkey -p

,測(cè)試一個(gè)或多個(gè)類別。

6. monkey調(diào)試類命令

adb shell monkey --dbg-no-events

監(jiān)視應(yīng)用程序所調(diào)用的包之間的轉(zhuǎn)換

adb shell monkey --hprof

在事件序列前后立即生成profiling report

adb shell monkey --ignore-crashes

讓monkey在應(yīng)用崩潰或異常后繼續(xù)發(fā)送事件直到計(jì)數(shù)完成

adb shell monkey --ignore-timeouts

讓monkey在任何超時(shí)錯(cuò)誤發(fā)生后繼續(xù)發(fā)送事件直到計(jì)數(shù)完成

adb shell monkey

--ignore-security-exceptions 讓monkey在應(yīng)用權(quán)限錯(cuò)誤發(fā)生后繼續(xù)發(fā)送事件直到計(jì)數(shù)完成

adb shell monkey --kill-process-after-error

讓monkey因?yàn)閼?yīng)用發(fā)生錯(cuò)誤而停止時(shí),將會(huì)通知系統(tǒng)停止發(fā)送錯(cuò)誤進(jìn)程

adb shell monkey --monitor-native-crashes

讓監(jiān)視并報(bào)告monkey運(yùn)行時(shí)Android系統(tǒng)native code的崩潰事件

adb shell monkey --wait-dbg

暫停執(zhí)行中的monkey,直到有調(diào)試器與它連接

7. monkey API

軌跡球事件

DispatchTrackball(long downTime,long eventTime, int action, float x, float y,float pressure, float size, int metaState, float xPrecision, float yPrecision,int device, int edgeFlags)

輸入字符串事件

DispatchString(String text)

點(diǎn)擊事件

DispatchPointer(long downTime,long eventTime, int action, float x, float y,float pressure, float size, int metaState, float xPrecision, float yPrecision,int device, int edgeFlags)

啟動(dòng)應(yīng)用

LaunchActivity(String pkg_name, Stringcl_name)

等待事件

UserWait(long sleeptime)

按下按鍵

DispatchPress(int keyCode)

長(zhǎng)按按鍵

LongPress(int keyCode)

發(fā)送按鍵

DispatchKey(long downTime, long eventTime,int action, int code, int repeat, int metaState, int device, int scancode)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容