1—–Android基於Monkey進行壓力測試

來源:互聯網
上載者:User

monkey是android中自待的一個壓力測試工具。

可以運行在模擬器裡或實際裝置中。它向系統發送偽隨機的使用者事件流,實現對正在開發的應用程式進行壓力測試

他的基本文法如下:
 monkey [options]

我們一般的用法:

monkey -p com.cx.ad(package) -v 500,鍵入此命令可以看到手機模擬器上進行中壓力測試。

下面是一個網上的例子(已經驗證過);

1.cmd進入所在盤的android-sdk-windows\platform-tools目錄裡面

2.在命令列輸入adb shell

3.輸入ls查看當前檔案夾下的目錄,執行結果如下

adb shell
# ls
ls
sqlite_stmt_journals
config
cache
sdcard
d
etc
system
sys
sbin
proc
init.rc
init.goldfish.rc
init
default.prop
data
root
dev

4.應用程式套件組合都在data下,我們輸入cd data進入data檔案夾,如下

# cd data
cd data

5.輸入ls查看檔案夾下的內容,如下所示:

# ls
ls
misc
local
data
app-private
app
property
anr
backup
dontpanic
dalvik-cache
system
lost+found

6.還有個data,所有的應用程式就在這個data下了, 進入這個data,然後輸入ls如下:

# cd data
cd data
# ls
ls
com.android.mms
com.android.providers.applications
com.android.globalsearch
com.android.calculator2
com.android.spare_parts
com.android.gesture.builder
com.android.music
com.android.sdksetup
com.android.packageinstaller
com.android.fallback
com.android.providers.settings
com.android.providers.drm
com.android.development
com.android.providers.telephony
com.android.inputmethod.pinyin
com.android.htmlviewer
com.android.settings
com.android.netspeed
com.android.providers.userdictionary
com.android.browser
com.android.contacts
com.android.alarmclock
com.android.camera
com.android.providers.contacts
jp.co.omronsoft.openwnn
com.android.launcher
com.android.phone
com.android.soundrecorder
com.google.android.providers.enhancedgooglesearch
com.svox.pico
com.android.customlocale
com.android.term
com.android.providers.downloads
com.android.providers.media
com.android.email
android.tts
com.android.inputmethod.latin
com.android.server.vpn
com.example.android.apis

7.最後一個就是我們剛才載入的APIDemo的應用程式套件組合

8.可以直接輸入monkey -p com.example.android.apis -v 50,結果如下,也可以退出shell,在命令列輸入,adb shell monkey -p com.example.android.apis -v 500 ,運行過程中,Emulator中的應用程式在不斷地切換畫面,可以看一下,呵呵:)

# monkey -p com.example.android.apis -v 50
monkey -p com.example.android.apis -v 50
:Monkey: seed=0 count=50
:AllowPackage: com.example.android.apis
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
//   0: 15.0%
//   1: 10.0%
//   2: 15.0%
//   3: 25.0%
//   4: 15.0%
//   5: 2.0%
//   6: 2.0%
//   7: 1.0%
//   8: 15.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10000000;component=com.example.android.apis/.ApiDemos
;end
// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.example.android.apis/.ApiDemos } in package com.
example.android.apis
:Sending Pointer ACTION_MOVE x=-4.0 y=2.0
:Sending Pointer ACTION_UP x=0.0 y=0.0
// Allowing start of Intent { cmp=com.example.android.apis/.ApiDemos } in pa
ckage com.example.android.apis
:Sending Pointer ACTION_DOWN x=207.0 y=282.0
:Sending Pointer ACTION_UP x=189.0 y=289.0
// Allowing start of Intent { cmp=com.example.android.apis/.app.Intents } in
package com.example.android.apis
:Sending Pointer ACTION_DOWN x=95.0 y=259.0
:Sending Pointer ACTION_UP x=95.0 y=259.0
:Sending Pointer ACTION_DOWN x=295.0 y=223.0
:Sending Pointer ACTION_UP x=290.0 y=213.0
:Sending Pointer ACTION_MOVE x=-5.0 y=3.0
:Dropped: keys=0 pointers=0 trackballs=0 flips=0
## Network stats: elapsed time=3799ms (3799ms mobile, 0ms wifi, 0ms not connecte
d)
// Monkey finished

至此完成測試,測試過程中可能會出現ANRs(“Application Not Responding"),說明有bug,

出現ANR,一般是主線程的響應超過5秒,或者BroadcastReceiver沒有在10秒內作出響應。這個就是一個比較嚴重的缺陷。

把耗時的操作另起線程來處理就可以了。

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.