1、首先测试设备是否连接成功,在命令行中输入:
adb devices
如果出现设备信息,代表链接成功。我这里的设备名称是“emulator-5554”
2、得到测试apk的包名,如果有APK源码包的话直接将“.apk”后缀改为“.zip”然后打开包中的AndroidManifest.xml可以查看包名,
如果没有或者已经安装的点击应用程序,然后查看logcat信息,也能够找到包名,同时在/data/data/目录下面有全部的应用程序的包名,
查询命令是:
adb shell
#cd /data/data
#ls
我们要测试的包名为:com.chaozh.iReaderFree
3、设定参数
首先用一个最简单的例子分析
adb shell monkey -p com.chaozh.iReaderFree -v -v -v 100
-p参数:表示指定测试的程序
-v参数:表示查看Monkey生成的一些详细的随机的事件名 数字100:表示测试事件数为100
4、结果分析
F:\>adb shell monkey -p com.chaozh.iReaderFree -v -v -v 100
:Monkey: seed=0 count=100
:AllowPackage: com.chaozh.iReaderFree
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Selecting main activities from category android.intent.category.LAUNCHER
// - NOT USING main activity com.android.calendar.AllInOneActivity (from packa
ge com.android.calendar)
// - NOT USING main activity com.android.music.MusicBrowserActivity (from pack
age com.android.music)
// - NOT USING main activity com.android.deskclock.DeskClock (from package com
.android.deskclock)
// - NOT USING main activity com.android.mms.ui.ConversationList (from package
com.android.mms)
// - NOT USING main activity com.android.email.activity.Welcome (from package
com.android.email)
// - NOT USING main activity com.android.camera.GalleryPicker (from package co
m.android.gallery)
// - NOT USING main activity com.android.settings.Settings (from package com.a
ndroid.settings)
// - NOT USING main activity com.android.browser.BrowserActivity (from package
com.android.browser)
// - NOT USING main activity com.android.camera.Camera (from package com.andro
id.camera)
// - NOT USING main activity com.android.contacts.activities.DialtactsActivity
(from package com.android.contacts)
// - NOT USING main activity com.android.contacts.activities.PeopleActivity (f
rom package com.android.contacts)
// - NOT USING main activity com.example.android.apis.ApiDemos (from package c
om.example.android.apis)
// - NOT USING main activity com.android.widgetpreview.WidgetPreviewActivity (
from package com.android.widgetpreview)
// - NOT USING main activity com.android.gesture.builder.GestureBuilderActivit
y (from package com.android.gesture.builder)
// + Using main activity com.chaozh.iReader.ui.activity.WelcomeActivity (from
package com.chaozh.iReaderFree)
// - NOT USING main activity com.android.customlocale2.CustomLocaleActivity (f
rom package com.android.customlocale2)
// - NOT USING main activity com.android.providers.downloads.ui.DownloadList (
from package com.android.providers.downloads.ui)
// - NOT USING main activity com.android.quicksearchbox.SearchActivity (from p
ackage com.android.quicksearchbox)
// - NOT USING main activity com.android.calculator2.Calculator (from package
com.android.calculator2)
// - NOT USING main activity com.android.speechrecorder.SpeechRecorderActivity
(from package com.android.speechrecorder)
// - NOT USING main activity com.android.development.Development (from package
com.android.development)
// - NOT USING main activity com.example.redmi.MainActivity (from package com.
example.redmi)
// - NOT USING main activity com.example.android_image.MainActivity (from pack
age com.example.android_image)
// - NOT USING main activity com.example.android_mp3.MainActivity (from packag
e com.example.android_mp3)
// - NOT USING main activity com.wiseweb.activity.Splash (from package com.wis
eweb.movie)
// Selecting main activities from category android.intent.category.MONKEY
// - NOT USING main activity com.android.launcher2.Launcher (from package com.
android.launcher)
// - NOT USING main activity com.android.settings.Settings$RunningServicesActi
vity (from package com.android.settings)
// - NOT USING main activity com.android.settings.Settings$StorageUseActivity
(from package com.android.settings)
// Seeded: 0
// Event percentages:
// 0: 15.0%
// 1: 10.0%
// 2: 2.0%
// 3: 15.0%
// 4: 25.0%
// 5: 15.0%
// 6: 2.0%
// 7: 2.0%
// 8: 1.0%
// 9: 13.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.categ
ory.LAUNCHER;launchFlags=0x10000000;component=com.chaozh.iReaderFree/com.chaozh.
iReader.ui.activity.WelcomeActivity;end
// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.in
tent.category.LAUNCHER] cmp=com.chaozh.iReaderFree/com.chaozh.iReader.ui.activit
y.WelcomeActivity } in package com.chaozh.iReaderFree
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 22 // KEYCODE_DPAD_RIGHT
:Sending Key (ACTION_UP): 22 // KEYCODE_DPAD_RIGHT
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 23 // KEYCODE_DPAD_CENTER
:Sending Key (ACTION_UP): 23 // KEYCODE_DPAD_CENTER
Sleeping for 0 milliseconds
:Sending Flip keyboardOpen=false
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 20 // KEYCODE_DPAD_DOWN
:Sending Key (ACTION_UP): 20 // KEYCODE_DPAD_DOWN
Sleeping for 0 milliseconds
:Sending Touch (ACTION_DOWN): 0:(153.0,207.0)
:Sending Touch (ACTION_UP): 0:(153.19875,207.49512)
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 82 // KEYCODE_MENU
:Sending Key (ACTION_UP): 82 // KEYCODE_MENU
Sleeping for 0 milliseconds
:Sending Touch (ACTION_DOWN): 0:(267.0,244.0)
:Sending Touch (ACTION_UP): 0:(272.7109,242.90211)
Sleeping for 0 milliseconds
:Sending Trackball (ACTION_MOVE): 0:(-1.0,-1.0)
:Sending Trackball (ACTION_MOVE): 0:(-5.0,0.0)
:Sending Trackball (ACTION_MOVE): 0:(3.0,4.0)
:Sending Trackball (ACTION_MOVE): 0:(0.0,4.0)
:Sending Trackball (ACTION_MOVE): 0:(3.0,-5.0)
:Sending Trackball (ACTION_MOVE): 0:(-2.0,0.0)
:Sending Trackball (ACTION_MOVE): 0:(1.0,3.0)
:Sending Trackball (ACTION_MOVE): 0:(-5.0,-3.0)
:Sending Trackball (ACTION_MOVE): 0:(3.0,-3.0)
:Sending Trackball (ACTION_MOVE): 0:(-2.0,1.0)
:Sending Key (ACTION_DOWN): 20 // KEYCODE_DPAD_DOWN
:Sending Key (ACTION_UP): 20 // KEYCODE_DPAD_DOWN
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 21 // KEYCODE_DPAD_LEFT
// Allowing start of Intent { cmp=com.chaozh.iReaderFree/com.zhangyue.iReade
r.read.ui.Activity_BookBrowser_TXT } in package com.chaozh.iReaderFree
:Sending Key (ACTION_UP): 21 // KEYCODE_DPAD_LEFT
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 46 // KEYCODE_R
:Sending Key (ACTION_UP): 46 // KEYCODE_R
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 23 // KEYCODE_DPAD_CENTER
:Sending Key (ACTION_UP): 23 // KEYCODE_DPAD_CENTER
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 21 // KEYCODE_DPAD_LEFT
:Sending Key (ACTION_UP): 21 // KEYCODE_DPAD_LEFT
Sleeping for 0 milliseconds
:Sending Trackball (ACTION_MOVE): 0:(1.0,-3.0)
:Sending Trackball (ACTION_MOVE): 0:(-5.0,3.0)
:Sending Trackball (ACTION_MOVE): 0:(-5.0,-1.0)
:Sending Trackball (ACTION_MOVE): 0:(2.0,-5.0)
:Sending Trackball (ACTION_MOVE): 0:(-2.0,2.0)
:Sending Trackball (ACTION_MOVE): 0:(-1.0,2.0)
:Sending Trackball (ACTION_MOVE): 0:(-4.0,-5.0)
:Sending Trackball (ACTION_MOVE): 0:(-3.0,-4.0)
:Sending Trackball (ACTION_MOVE): 0:(-2.0,2.0)
:Sending Trackball (ACTION_MOVE): 0:(1.0,3.0)
:Sending Key (ACTION_DOWN): 82 // KEYCODE_MENU
:Sending Key (ACTION_UP): 82 // KEYCODE_MENU
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 178 // KEYCODE_TV_INPUT
:Sending Key (ACTION_UP): 178 // KEYCODE_TV_INPUT
Sleeping for 0 milliseconds
:Sending Trackball (ACTION_MOVE): 0:(-1.0,-2.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,3.0)
:Sending Trackball (ACTION_MOVE): 0:(-5.0,2.0)
:Sending Trackball (ACTION_MOVE): 0:(0.0,2.0)
:Sending Trackball (ACTION_MOVE): 0:(0.0,3.0)
:Sending Trackball (ACTION_MOVE): 0:(-4.0,0.0)
:Sending Trackball (ACTION_MOVE): 0:(-2.0,0.0)
:Sending Trackball (ACTION_MOVE): 0:(-4.0,2.0)
:Sending Trackball (ACTION_MOVE): 0:(2.0,1.0)
:Sending Trackball (ACTION_MOVE): 0:(-2.0,4.0)
:Sending Trackball (ACTION_DOWN): 0:(0.0,0.0)
:Sending Trackball (ACTION_UP): 0:(0.0,0.0)
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 3 // KEYCODE_HOME
:Sending Key (ACTION_UP): 3 // KEYCODE_HOME
// Rejecting start of Intent { act=android.intent.action.MAIN cat=[android.i
ntent.category.HOME] cmp=com.android.launcher/com.android.launcher2.Launcher } i
n package com.android.launcher
Sleeping for 0 milliseconds
:Sending Touch (ACTION_DOWN): 0:(257.0,143.0)
:Sending Touch (ACTION_UP): 0:(248.47726,134.0601)
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 126 // KEYCODE_MEDIA_PLAY
:Sending Key (ACTION_UP): 126 // KEYCODE_MEDIA_PLAY
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 20 // KEYCODE_DPAD_DOWN
:Sending Key (ACTION_UP): 20 // KEYCODE_DPAD_DOWN
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 21 // KEYCODE_DPAD_LEFT
:Sending Key (ACTION_UP): 21 // KEYCODE_DPAD_LEFT
Sleeping for 0 milliseconds
:Sending Trackball (ACTION_MOVE): 0:(-1.0,-2.0)
:Sending Trackball (ACTION_MOVE): 0:(1.0,1.0)
:Sending Trackball (ACTION_MOVE): 0:(-1.0,-2.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,2.0)
:Sending Trackball (ACTION_MOVE): 0:(3.0,4.0)
:Sending Trackball (ACTION_MOVE): 0:(2.0,-4.0)
:Sending Trackball (ACTION_MOVE): 0:(-5.0,-2.0)
:Sending Trackball (ACTION_MOVE): 0:(-4.0,-1.0)
:Sending Trackball (ACTION_MOVE): 0:(-4.0,-2.0)
:Sending Trackball (ACTION_MOVE): 0:(-2.0,3.0)
:Sending Touch (ACTION_DOWN): 0:(33.0,453.0)
:Sending Touch (ACTION_POINTER_DOWN 1): 0:(37.53572,452.94702) 1:(283.0,88.0)
:Sending Touch (ACTION_MOVE): 0:(38.494465,452.9393) 1:(289.34943,87.55577)
:Sending Touch (ACTION_POINTER_UP 1): 0:(44.913345,452.7924) 1:(295.43988,87.318
954)
:Sending Touch (ACTION_UP): 0:(47.022545,452.70322)
Sleeping for 0 milliseconds
:Sending Touch (ACTION_DOWN): 0:(300.0,208.0)
:Sending Touch (ACTION_MOVE): 0:(301.1697,213.4518)
:Sending Touch (ACTION_MOVE): 0:(304.233,218.98541)
:Sending Touch (ACTION_MOVE): 0:(305.48483,225.51746)
:Sending Touch (ACTION_MOVE): 0:(307.53262,234.67958)
:Sending Touch (ACTION_MOVE): 0:(310.49463,238.96536)
:Sending Touch (ACTION_MOVE): 0:(312.6929,247.50093)
:Sending Touch (ACTION_MOVE): 0:(314.07666,254.9053)
:Sending Touch (ACTION_MOVE): 0:(315.71674,256.64383)
:Sending Touch (ACTION_UP): 0:(318.2656,263.68002)
Sleeping for 0 milliseconds
:Sending Trackball (ACTION_MOVE): 0:(-1.0,-4.0)
:Sending Trackball (ACTION_MOVE): 0:(2.0,1.0)
:Sending Trackball (ACTION_MOVE): 0:(-5.0,2.0)
:Sending Trackball (ACTION_MOVE): 0:(2.0,-5.0)
:Sending Trackball (ACTION_MOVE): 0:(-4.0,-1.0)
Events injected: 100
:Dropped: keys=2 pointers=3 trackballs=0 flips=0
## Network stats: elapsed time=12388ms (12388ms mobile, 0ms wifi, 0ms not connec
ted)
// Monkey finished