一、Monkey是什么
Monkey是Android中的一个命令行工具,它其实就是SDK中附带的一个工具,可以运行在模拟器里或实际设备中。
二、Monkey测试的目的
Monkey测试是Android平台自动化测试的一种手段,通过Monkey程序模拟用户的按键输入,触摸屏输入,手势输入等操作来对设备上的程序进行压力测试,检测程序多久的时间会发生异常。该工具主要用于进行压力测试,开发人员结合monkey打印的日志解决测试中出现的问题。
三、Monkey测试的特点
1、测试的对象仅为应用程序包,有一定的局限性。
2、Monkey测试,所有的事件都是随机产生的,不带任何人的主观性。
3、可对MonkeyTest的对象,事件数量,类型,频率等进行设置。
四、Monkey的使用场景
APP开发过程中的各个阶段:提测、集成、et等。
五、Monkey的使用及命令详解
1、每个命令的详细解释
--help 列出简单的用法。
-v
命令行的每一个-v将增加反馈信息的级别。Level 0(缺省值)除启动提示、测试完成和最终结果之外,提供较少信息。Level 1 提供较为详细的测试信息,如逐个发送到Activity的事件。Level 2 提供更加详细的设置信息,如测试中被选中的或未被选中的Activity事件
-s
伪随机数生成器的seed值。如果用相同的seed值再次运行Monkey,它将生成相同的事件序列。
--throttle
在事件之间插入固定延迟。通过这个选项可以减缓Monkey的执行速度。如果不指定该选项,Monkey将不会被延迟,事件将尽可能快地被产成。
--pct-touch
调整触摸事件的百分比(触摸事件是一个down-up事件,它发生在屏幕上的某单一位置)。
--pct-motion
调整动作事件的百分比(动作事件由屏幕上某处的一个down事件、一系列的伪随机事件和一个up事件组成)。
--pct-trackball
调整轨迹事件的百分比(轨迹事件由一个或几个随机的移动组成,有时还伴随有点击)。
--pct-nav
调整“基本”导航事件的百分比(导航事件由来自方向输入设备的up/down/left/right组成)。
--pct-majornav
调整“主要”导航事件的百分比(这些导航事件通常引发图形界面中的动作,如:5-way键盘的中间按键、回退按键、菜单按键)
--pct-syskeys
调整“系统”按键事件的百分比(这些按键通常被保留,由系统使用,如Home、Back、Start Call、End Call及音量控制键)。
--pct-appswitch
调整启动Activity的百分比。在随机间隔里,Monkey将执行一个startActivity()调用,作为最大程度覆盖包中全部Activity的一种方法。
--pct-anyevent
调整其它类型事件的百分比。它包罗了所有其它类型的事件,如:按键、其它不常用的设备按钮、等等。约束限制
-p
如果用此参数指定了一个或几个包,Monkey将只允许系统启动这些包里的Activity。如果你的应用程序还需要访问其它包里的Activity(如选 择取一个联系人),那些包也需要在此同时指定。如果不指定任何包,Monkey将允许系统启动全部包里的Activity。要指定多个包,需要使用多个
-p
选项,每个-p选项只能用于一个包。
-c
如 果用此参数指定了一个或几个类别,Monkey将只允许系统启动被这些类别中的某个类别列出的Activity。如果不指定任何类别,Monkey将选择 下列类别中列出的Activity:Intent.CATEGORY_LAUNCHER或Intent.CATEGORY_MONKEY。要指定多个类 别,需要使用多个-c选项,每个-c选项只能用于一个类别调试
--dbg-no-events
设置此选项,Monkey将执行初始启动,进入到一个测试Activity,然后不会再进一步生成事件。为了得到最佳结果,把它与-v、一个或几个包约束、以及一个保持Monkey运行30秒或更长时间的非零值联合起来,从而提供一个环境,可以监视应用程序所调用的包之间的转换。
--hprof
设置此选项,将在Monkey事件序列之前和之后立即生成profiling报告。这将会在data/misc中生成大文件(~5Mb),所以要小心使用它。
--ignore-crashes
通常,当应用程序崩溃或发生任何失控异常时,Monkey将停止运行。如果设置此选项,Monkey将继续向系统发送事件,直到计数完成。
--ignore-timeouts
通常,当应用程序发生任何超时错误(如“Application Not Responding”对话框)时,Monkey将停止运行。如果设置此选项,Monkey将继续向系统发送事件,直到计数完成。
--ignore-security-exceptions
通常,当应用程序发生许可错误(如启动一个需要某些许可的Activity) 时,Monkey将停止运行。如果设置了此选项,Monkey将继续向系统发送事件,直到计数完成。
--kill-process-after-error
通常,当Monkey由于一个错误而停止时,出错的应用程序将继续处于运行状态。当设置了此选项时,将会通知系统停止发生错误的进程。注意,正常的(成功的)结束,并没有停止启动的进程,设备只是在结束事件之后,简单地保持在最后的状态。
--monitor-native-crashes
监视并报告Android系统中本地代码的崩溃事件。如果设置了--kill- process-after-error,系统将停止运行。--wait-dbg停止执行中的Monkey,直到有调试器和它相连接。
2.monkey的简单示例
adb shell monkey -p com.ganji.android.haoche_c -s 100 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --monitor-native-crashes --throttle 100 -v -v 100>e:\monkeytest1008.txt
【命令释义monkey作用的包:com.ganji.android.haoche_c
产生时间序列的种子值:100,忽略程序崩溃、忽略超时、忽略程序错误、监视本地程序崩溃、事件之间延迟时间设定为100ms、日志详细信息级别为2 , 产生100个事件,日志写入e盘的monkeytest1008.txt文档中 。】
五、Monkey日志分析
:Monkey: seed=100 count=100 /* seed:随机种子数;count:事件总数 */
:AllowPackage: com.ganji.android.haoche_c /* 包名 */
: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.bbkmusic.WidgetToTrackActivity (from package com.android.bbkmusic)
// - NOT USING main activity com.android.bbksoundrecorder.SoundRecorder (from package com.android.bbksoundrecorder)
// - NOT USING main activity com.android.camera.CameraActivity (from package com.android.camera)
// - NOT USING main activity com.android.contacts.DialtactsContactsEntryActivity (from package com.android.contacts)
// - NOT USING main activity com.android.dialer.TwelveKeyDialer (from package com.android.dialer)
// - NOT USING main activity com.android.mms.ui.ConversationList (from package com.android.mms)
// - NOT USING main activity com.android.settings.Settings (from package com.android.settings)
// - NOT USING main activity com.bbk.calendar.MainActivity (from package com.bbk.calendar)
// - NOT USING main activity com.bbk.theme.Theme (from package com.bbk.theme)
// - NOT USING main activity com.chaozh.iReader.ui.activity.WelcomeActivity (from package com.chaozh.iReader)
// - NOT USING main activity com.vivo.email.activity.Welcome (from package com.vivo.email)
// - NOT USING main activity com.android.gallery3d.vivo.GalleryTabActivity (from package com.vivo.gallery)
// - NOT USING main activity com.google.android.apps.chrome.Main (from package com.android.chrome)
// - NOT USING main activity com.cubic.autohome.LogoActivity (from package com.cubic.autohome)
// - NOT USING main activity org.hapjs.mockup.activity.MainActivity (from package org.hapjs.mockup)
// - NOT USING main activity com.android.BBKClock.Timer (from package com.android.BBKClock)
// - NOT USING main activity com.vivo.video.app.splash.SplashActivity (from package com.android.VideoPlayer)
// - NOT USING main activity com.android.bbkcalculator.Calculator (from package com.android.bbkcalculator)
// - NOT USING main activity com.android.filemanager.FileManagerActivity (from package com.android.filemanager)
// - NOT USING main activity com.android.notes.Notes (from package com.android.notes)
// - NOT USING main activity com.bbk.appstore.ui.AppStore (from package com.bbk.appstore)
// - NOT USING main activity com.bbk.cloud.activities.BBKCloudHomeScreen (from package com.bbk.cloud)
// - NOT USING main activity com.iqoo.secure.MainGuideActivity (from package com.iqoo.secure)
// - NOT USING main activity com.vivo.Tips.MainActivity (from package com.vivo.Tips)
// - NOT USING main activity com.vivo.browser.BrowserActivity (from package com.vivo.browser)
// - NOT USING main activity com.vivo.childrenmode.activity.ChildHomeActivity (from package com.vivo.childrenmode)
// - NOT USING main activity com.vivo.compass.CalibrationActivity (from package com.vivo.compass)
// - NOT USING main activity com.vivo.game.ui.LogoActivity (from package com.vivo.game)
// - NOT USING main activity com.vivo.space.ui.LogoActivity (from package com.vivo.space)
// - NOT USING main activity com.vivo.weather.WeatherMain (from package com.vivo.weather)
// - NOT USING main activity com.UCMobile.main.UCMobile (from package com.UCMobile)
// - NOT USING main activity com.android.bbk.lockscreen3.LockScreenActivity (from package com.android.bbk.lockscreen3)
// - NOT USING main activity com.bbk.iqoo.feedback.activities.UserFeedBackActivity (from package com.bbk.iqoo.feedback)
// - NOT USING main activity com.guazi.crm.modules.splash.SplashActivity (from package com.ganji.android.haoche)
// - NOT USING main activity com.squareup.leakcanary.internal.DisplayLeakActivity (from package com.ganji.android.haoche)
// - NOT USING main activity com.github.moduth.blockcanary.ui.DisplayActivity (from package com.ganji.android.haoche)
// + Using main activity com.ganji.android.haoche_c.ui.main.MainActivity (from package com.ganji.android.haoche_c)
// - NOT USING main activity com.guazi.android.expert.activity.SplashLoginActivity (from package com.guazi.android.expert)
// - NOT USING main activity com.guazi.newcar.modules.splash.SplashActivity (from package com.guazi.newcar)
// - NOT USING main activity com.squareup.leakcanary.internal.DisplayLeakActivity (from package com.guazi.newcar)
// - NOT USING main activity com.guazi.polaris.SplashActivity (from package com.guazi.polaris)
// - NOT USING main activity com.ijinshan.browser.screen.SplashActivity (from package com.ijinshan.browser_fast)
// - NOT USING main activity com.jingdong.app.mall.main.MainActivity (from package com.jingdong.app.mall)
// - NOT USING main activity com.lucky.luckyclient.splash.splash.SplashActivity (from package com.lucky.luckyclient)
// - NOT USING main activity com.maintain.verify.activity.SplashActivity (from package com.maintain.verify)
// - NOT USING main activity com.renrenche.carapp.ui.activity.SplashActivity (from package com.renrenche.carapp)
// - NOT USING main activity com.meituan.android.pt.homepage.activity.Welcome (from package com.sankuai.meituan)
// - NOT USING main activity com.sina.weibo.SplashActivity (from package com.sina.weibo)
// - NOT USING main activity com.taobao.tao.welcome.Welcome (from package com.taobao.taobao)
// - NOT USING main activity com.tencent.mm.ui.LauncherUI (from package com.tencent.mm)
// - NOT USING main activity com.tencent.mobileqq.activity.SplashActivity (from package com.tencent.mobileqq)
// - NOT USING main activity com.tencent.mtt.SplashActivity (from package com.tencent.mtt)
// - NOT USING main activity com.tencent.news.activity.SplashActivity (from package com.tencent.news)
// - NOT USING main activity com.tencent.qqlive.ona.activity.WelcomeActivity (from package com.tencent.qqlive)
// - NOT USING main activity com.uxin.usedcar.ui.fragment.SplashActivity (from package com.uxin.usedcar)
// - NOT USING main activity com.vivo.easyshare.activity.SplashScreenActivity (from package com.vivo.easyshare)
// - NOT USING main activity com.pp.assistant.activity.PPMainActivity (from package com.wandoujia.phoenix2)
// - NOT USING main activity com.wuba.activity.launch.LaunchActivity (from package com.wuba)
// - NOT USING main activity com.zhihu.android.app.ui.activity.LauncherActivity (from package com.zhihu.android)
// - NOT USING main activity ctrip.business.splash.CtripSplashActivity (from package ctrip.android.view)
// - NOT USING main activity io.appium.settings.Settings (from package io.appium.settings)
// - NOT USING main activity io.appium.unlock.Unlock (from package io.appium.unlock)
// - NOT USING main activity org.hapjs.debugger.MainActivity (from package org.hapjs.debugger)
// - NOT USING main activity sogou.mobile.explorer.NoDisplayActivity (from package sogou.mobile.explorer)
// Selecting main activities from category android.intent.category.MONKEY
// - NOT USING main activity com.android.settings.Settings$RunningServicesActivity (from package com.android.settings)
// - NOT USING main activity com.android.settings.Settings$StorageUseActivity (from package com.android.settings)
// - NOT USING main activity com.bbk.launcher2.Launcher (from package com.bbk.launcher2)
// - NOT USING main activity com.bbk.scene.launcher.theme.SceneLauncherThemeMainActivity (from package com.bbk.scene.launcher.theme)
// - NOT USING main activity com.iqoo.engineermode.EngineerMode (from package com.iqoo.engineermode)
// - NOT USING main activity com.vivo.childrenmode.activity.MainActivity (from package com.vivo.childrenmode)
// Seeded: 100
// Event percentages:
// 0: 15.0% /* 0:触摸事件百分比,即参数--pct-touc */
// 1: 10.0% /* 1:滑动事件百分比,即参数--pct-motion */
// 2: 2.0% /* 2:缩放事件百分比,即参数--pct-pinchzoom */
// 3: 15.0% /* 3:轨迹球事件百分比,即参数--pct-trackball */
// 4: -0.0% /* 4:屏幕旋转事件百分比,即参数--pct-rotation */
// 5: -0.0% /* 5:基本导航事件百分比,即参数--pct-nav */
// 6: 25.0% /* 6:主要导航事件百分比,即参数--pct-majornav */
// 7: 15.0% /* 7:系统事件百分比,即参数--pct-syskeys */
// 8: 2.0% /* 8:Activity启动事件百分比,即参数--pct-appswitch */
// 9: 2.0% /* 9:键盘翻转事件百分比,即参数--pct-flip */
// 10: 14.0% /* 10:其他事件百分比,即参数--pct-anyevent */
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.ganji.android.haoche_c/.ui.main.MainActivity;end
// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.ganji.android.haoche_c/.ui.main.MainActivity } in package com.ganji.android.haoche_c
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 82 // KEYCODE_MENU
:Sending Key (ACTION_UP): 82 // KEYCODE_MENU
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 Touch (ACTION_DOWN): 0:(236.0,1448.0)
:Sending Touch (ACTION_UP): 0:(239.6952,1450.5131)
Sleeping for 0 milliseconds
:Sending Touch (ACTION_DOWN): 0:(817.0,672.0)
:Sending Touch (ACTION_MOVE): 0:(806.7215,674.58936)
// Rejecting start of Intent { cmp=com.vivo.upslide/.recents.RecentsActivity } in package com.vivo.upslide
:Sending Touch (ACTION_MOVE): 0:(796.983,678.33875)
:Sending Touch (ACTION_MOVE): 0:(777.5646,682.8886)
:Sending Touch (ACTION_MOVE): 0:(760.08307,683.68207)
:Sending Touch (ACTION_MOVE): 0:(753.2682,686.4697)
:Sending Touch (ACTION_MOVE): 0:(744.06885,686.58435)
:Sending Touch (ACTION_MOVE): 0:(732.9116,692.0274)
:Sending Touch (ACTION_MOVE): 0:(720.2788,693.7811)
:Sending Touch (ACTION_UP): 0:(704.8928,701.56537)
Sleeping for 0 milliseconds
:Sending Touch (ACTION_DOWN): 0:(268.0,1826.0)
:Sending Touch (ACTION_UP): 0:(264.17523,1823.462)
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 19 // KEYCODE_DPAD_UP
:Sending Key (ACTION_UP): 19 // KEYCODE_DPAD_UP
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): 19 // KEYCODE_DPAD_UP
:Sending Key (ACTION_UP): 19 // KEYCODE_DPAD_UP
Sleeping for 0 milliseconds
:Sending Touch (ACTION_DOWN): 0:(336.0,359.0)
:Sending Touch (ACTION_MOVE): 0:(340.20886,357.3222)
:Sending Touch (ACTION_MOVE): 0:(342.71722,353.41183)
:Sending Touch (ACTION_MOVE): 0:(346.9966,350.894)
:Sending Touch (ACTION_MOVE): 0:(355.95114,348.16638)
:Sending Touch (ACTION_MOVE): 0:(358.57358,344.2732)
:Sending Touch (ACTION_UP): 0:(367.2303,344.00336)
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 242 // KEYCODE_TV_ANTENNA_CABLE
:Sending Key (ACTION_UP): 242 // KEYCODE_TV_ANTENNA_CABLE
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:(-4.0,-1.0)
:Sending Trackball (ACTION_MOVE): 0:(-2.0,-3.0)
:Sending Trackball (ACTION_MOVE): 0:(-3.0,2.0)
:Sending Trackball (ACTION_MOVE): 0:(-2.0,1.0)
:Sending Trackball (ACTION_MOVE): 0:(1.0,3.0)
:Sending Trackball (ACTION_MOVE): 0:(-2.0,-1.0)
:Sending Trackball (ACTION_MOVE): 0:(-4.0,-1.0)
:Sending Trackball (ACTION_MOVE): 0:(-3.0,-2.0)
:Sending Trackball (ACTION_MOVE): 0:(3.0,1.0)
:Sending Trackball (ACTION_MOVE): 0:(3.0,-5.0)
:Sending Key (ACTION_DOWN): 23 // KEYCODE_DPAD_CENTER
:Sending Key (ACTION_UP): 23 // KEYCODE_DPAD_CENTER
Sleeping for 0 milliseconds
:Sending Touch (ACTION_DOWN): 0:(546.0,1255.0)
:Sending Touch (ACTION_UP): 0:(538.475,1257.1292)
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 Touch (ACTION_DOWN): 0:(788.0,1096.0)
:Sending Touch (ACTION_UP): 0:(785.90125,1099.7758)
Sleeping for 0 milliseconds
:Sending Touch (ACTION_DOWN): 0:(440.0,1768.0)
:Sending Touch (ACTION_MOVE): 0:(443.97714,1764.4805)
:Sending Touch (ACTION_MOVE): 0:(452.77997,1757.93)
:Sending Touch (ACTION_MOVE): 0:(454.22604,1757.2743)
:Sending Touch (ACTION_MOVE): 0:(463.5927,1757.0007)
:Sending Touch (ACTION_MOVE): 0:(472.0165,1752.8053)
:Sending Touch (ACTION_MOVE): 0:(475.4624,1751.4882)
:Sending Touch (ACTION_MOVE): 0:(482.6616,1745.5962)
:Sending Touch (ACTION_UP): 0:(489.12665,1742.0593)
Sleeping for 0 milliseconds
:Sending Flip keyboardOpen=false
Got IOException performing flipjava.io.IOException: write failed: EINVAL (Invalid argument)
// Injection Failed
Sleeping for 0 milliseconds
:Sending Trackball (ACTION_MOVE): 0:(-4.0,0.0)
:Sending Trackball (ACTION_MOVE): 0:(-2.0,-4.0)
// Allowing start of Intent { cmp=com.ganji.android.haoche_c/.ui.html5.Html5Activity } in package com.ganji.android.haoche_c
:Sending Trackball (ACTION_MOVE): 0:(3.0,1.0)
:Sending Trackball (ACTION_MOVE): 0:(3.0,3.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,-4.0)
:Sending Trackball (ACTION_MOVE): 0:(2.0,2.0)
:Sending Trackball (ACTION_MOVE): 0:(-3.0,-3.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,-4.0)
:Sending Trackball (ACTION_MOVE): 0:(0.0,3.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,0.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): 20 // KEYCODE_DPAD_DOWN
:Sending Key (ACTION_UP): 20 // KEYCODE_DPAD_DOWN
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 135 // KEYCODE_F5
:Sending Key (ACTION_UP): 135 // KEYCODE_F5
Sleeping for 0 milliseconds
:Sending Trackball (ACTION_MOVE): 0:(-4.0,-4.0)
:Sending Trackball (ACTION_MOVE): 0:(0.0,-4.0)
:Sending Trackball (ACTION_MOVE): 0:(-5.0,4.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,3.0)
:Sending Trackball (ACTION_MOVE): 0:(2.0,-1.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,-3.0)
:Sending Trackball (ACTION_MOVE): 0:(1.0,3.0)
:Sending Trackball (ACTION_MOVE): 0:(0.0,-1.0)
:Sending Trackball (ACTION_MOVE): 0:(-3.0,0.0)
:Sending Trackball (ACTION_MOVE): 0:(4.0,-5.0)
:Sending Key (ACTION_DOWN): 22 // KEYCODE_DPAD_RIGHT
:Sending Key (ACTION_UP): 22 // KEYCODE_DPAD_RIGHT
Sleeping for 0 milliseconds
:Sending Key (ACTION_DOWN): 19 // KEYCODE_DPAD_UP
:Sending Key (ACTION_UP): 19 // KEYCODE_DPAD_UP
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 Trackball (ACTION_MOVE): 0:(3.0,-4.0)
:Sending Trackball (ACTION_MOVE): 0:(2.0,-4.0)
:Sending Trackball (ACTION_MOVE): 0:(-2.0,1.0)
:Sending Trackball (ACTION_MOVE): 0:(0.0,-2.0)
Events injected: 100
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=1 rotations=0
## Network stats: elapsed time=483ms (0ms mobile, 0ms wifi, 483ms not connected)
// Monkey finished
查看Monkey日志,初步分析方法:
Monkey测试出现错误后,一般的差错步骤为以下几步:
1、 找到是monkey里面的哪个地方出错(如(快捷键Ctrl+f)搜索crash,查看crash位置前后是否有当前app的包名,如果有,则定位到crash由app引起的)
2、 查看Monkey里面出错前的一些事件动作,并手动执行该动作
3、 若以上步骤还不能找出,可以使用之前执行的monkey命令再执行一遍,注意seed值要一样
一般的测试结果分析:
1、 ANR问题(无响应问题):在日志中搜索“ANR”
2、 崩溃问题:在日志中搜索“Exception”
六、个人在Monkey中常遇见的问题
1、 真机用adb shell命令时出现以下提示:
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
error: device not found
解决方案:①查看下手机设置 USB Debugging 是否开启?
②试试重启adb:adb kill-server
adb start-server
adb remount
③小米手机需要在弹出的对话框点确定允许调试。
2、跑monkey的时候想抓程序log导出时,有时会提示:cannot create D:monkeytest.txt: read-only file system
为什么有时候可以有时候不可以?后来发现跟使用使用习惯不一样有关。有时候是先进入adb shell 再用命令,有时候是直接命令进入。进入adb shell后再用命令就会失败,进入adb shell后就相当于进入linux的root下面,没有权限在里面创建文件。正确方法:退出shell或者执行命令时先不要进shell。
3、跑monkey的时候,如果出现特殊情况需要强行停止,如(断网等干扰)
停止monkey的方式:1、adb shell(登录设备) 2、top|grep "monkey" (实时查询monkey的进程号) 3、kill -9 31819(-9:强制杀死进程;31819为查询出来的进程号)
4、monkey的随机事件可以帮助我们发现app中的一些缺陷,但是这些“随机”也会给我们带来一些困扰
手机经常会在一个页面出不去,其他业务测试不到
手机网络关掉后,导致APP大部分在无网情况下运行,一些业务测试不到
怎样才能知道手机跑monkey时候的运行状态,如内存
1.手机经常会在一个页面出不去,其他业务测试不到
手机会困在一个页面出不去。那我们需要做的就是在跑Monkey的间隔把APP从页面推出去。
一个方法是使用“back”键退出程序:adb shell input keyevent 4 循环几次就可以退出去了
但是现实中还是有退不出的情况,怎么办?
另一个方案就是强制退出:adb shell am force-stop yourPkgName
2.手机网络关掉后,导致APP大部分在无网情况下运行,一些业务测试不到
目前的方案就是停止monkey,在网络环境好的情况下重新跑monkey:1、adb shell(登录设备) 2、top|grep "monkey" (实时查询monkey的进程号) 3、kill -9 31819(-9:强制杀死进程;31819为查询出来的进程号)
3.怎样才能知道手机跑monkey时候的运行状态,如内存
adb shell cat /proc/meminfo
运行这个命令,就可以获取相关的内存信息了。