1-----Android基于Monkey进行压力测试

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秒内作出响应。这个就是一个比较严重的缺陷。

把耗时的操作另起线程来处理就可以了。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值