Android之monkeyTest

一.Monkey简介

创新互联建站专注于绥芬河网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供绥芬河营销型网站建设,绥芬河网站制作、绥芬河网页设计、绥芬河网站官网定制、小程序定制开发服务,打造绥芬河网络公司原创品牌,更为您提供绥芬河网站排名全网营销落地服务。

Monkey是Android中的一个命令行工具,可以运行在模拟器里或实际设备中。它向系统发送伪随机的用户事件流(如按键输入、触摸屏输入、手势输入等),实现对正在开发的应用程序进行测试。Monkey测试是一种为了测试软件的稳定性、健壮性的快速有效的方法。

 

二、Monkey程序介绍

1) Monkey程序由Android系统自带,使用Java语言写成,在Android文件系统中的存放路径是:/system/framework/monkey.jar;

2) Monkey.jar程序是由一个名为“monkey”的Shell脚本来启动执行,shell脚本在Android文件系统中的存放路径是:/system/bin/monkey;

我们就可以通过在cmd窗口执行adb shell monkey {+命令参数}来进行monkey测试了。

下边就是monkey中的一些常用指令:

Android之monkey Test

三、Monkey测试前的准备

1.准备一张sd卡(或者手机有内置sd卡),以便测试中存储缓存或者图片信息。

2.执行monkey测试前,一定要确保屏幕处于解锁状态。

3.设置屏幕超时时间为最大时间(设置->显示->休眠->30分钟或者从不)。以防测试过程中手机锁屏,影响monkey测试。

4.打开usb调试,确保adb可以连接。

5.抓取adb log,(如果出现anr,需要将/data/anr/下的anr log拿出来)。

 

四、Monkey测试命令

1.测试命令:

adb shell monkey -p  包名 --ignore-timeouts --ignore-crashes--ignore-security-exceptions -v -v --throttle 200 1000000

 

例如我们的app进行测试,命令如下:

adb shell monkey -p  com.test  --ignore-timeouts --ignore-crashes--ignore-security-exceptions  -v -v --throttle500 1000000

我们在测试过程中,建议不要忽略这些异常,尽可能的暴露出app中存在的问题,如果选择忽略出现crash,anr等现象,手机中就不会有提示,不便于判断测试是否正常。忽略异常是想要对此模块执行完成,尽可能多的发现更多问题,但是这个问题的判断只能通过log去分析,不便于测试的判断。所以我们测试建议使用下边的命令:

adb shell monkey  -p  包名 –v -v -v --throttle 500 1000000 >e:\monkeylog.txt

 

 

各个参数的意义如下:

-P   

用于约束限制,用此参数指定一个或多个包(Package)。指定包之后,Monkey将只允许系统启动指定的APP。如果不指定包,Monkey将允许系统启动设备中的所有APP。

--ignore-crashes

用于指定当应用程序崩溃时(Force & Close错误),Monkey是否停止运行。如果使用此参数,即使应用程序崩溃,Monkey依然会发送事件,直到事件计数完成。

--ignore-timeouts

用于指定当应用程序发生ANR(Application No Responding)错误时,Monkey是否停止运行。如果使用此参数,即使应用程序发生ANR错误,Monkey依然会发送事件,直到事件计数完成。

--ignore-security-exceptions

用于指定当应用程序发生许可错误时(如证书许可,网络许可等),Monkey是否停止运行。如果使用此参数,即使应用程序发生许可错误,Monkey依然会发送事件,直到事件计数完成。

 

 -v

用于指定反馈信息级别(信息级别就是日志的详细程度),总共分3个级别,分别对应的参数如下表所示:

 

日志级别 Level 0 

示例:adb shell monkey -p  com.android.contacts  -v --throttle 200 1000000

缺省值,仅提供启动提示、测试完成和最终结果等少量信息

 

日志级别Level 1

示例:adb shell monkey -p  com.android.contacts–v -v --throttle 200 1000000

 提供较为详细的日志,包括每个发送到Activity的事件信息

 

日志级别Level 2

示例:adb shellmonkey -p  com.android.contacts–v –v -v --throttle 200 1000000

提供最详细的日志,包括了测试中选中/未选中的Activity信息

 

--throttle

在每两次操作(即事件)间的时延,单位是毫秒,一般我们设置延时时间为500ms,比较接近人的手动操作,如果在测试中发生了anr,可以将间隔设置为500ms,进行测试验证。

 

-s

S其实就seed,它是随机数的事件序列定一个值,若出现问题下次可以重复同样的序列进行排错。

下面其实就是指定了一个seed为1080的随机事件序列。

adb shell monkey -s 1080 -p  com.android.contacts–v -v --throttle 200 1000000

 

2.  Monkey测试中的黑名单和白名单

在测试中,因为手机中的一些其他操作可能影响测试结果(例如下拉通知栏),我们可以进行设置一个类似黑名单的东西去屏蔽它,具体命令如下:

adb shell monkey --pkg-blacklist-file /data/ blacklist.txt -v -v--throttle 200 1000000

具体的实现方式是,首先在电脑上建立一个blacklist.txt文件,在这个文件中将要屏蔽的包名一一写进去,然后将这个文件push到手机的data目录下: adbpush blacklist.txt /data/,这样就会屏蔽掉这几个包,不去执行它。下面是我建的一个blacklist.txt文件。

Android之monkey Test

 

和黑名单类似,我们也可以建立一个类似于白名单一样的文件whitelist.txt,只去执行在白名单列表中的包名(我们测试过程中可把我们自己app的包名加到这个文件中),详细步骤和黑名单一样,这里不在赘述。具体命令如下:

adb shell monkey --pkg-whitelist-file /data/whitelist.txt -v -v --throttle 5001000000

 

五、Monkey测试pass或者fail的判断

 

1. monkey测试正常结束(pass)的判断

 

如果正常完成monkey测试,会在最好的monke log中打印出:

Monkey finished的字样。下面是setting模块monkey测试pass的log。

 

 

// Allowing start of Intent {act=android.intent.action.MAIN cmp=com.android.settings/.SubSettings } inpackage com.android.settings

    //activityResuming(com.android.settings)

:Sending Trackball (ACTION_MOVE):0:(-3.0,3.0)

:Sending Trackball (ACTION_MOVE): 0:(4.0,4.0)

:Sending Touch (ACTION_DOWN): 0:(642.0,499.0)

Events injected: 300000

:Sending rotation degree=0, persist=false

:Dropped: keys=0 pointers=0 trackballs=0flips=0 rotations=0

## Network stats: elapsed time=35892101ms(0ms mobile, 0ms wifi, 35892101ms not connected)

// Monkey finished

 

 

2. monkey测试非正常结束(fail)的判断

(1)monkey测试中出现停止运行(crash)现象

下边是以前测试浏览器出现的停止运行现象,monkey log如下:

在monkeylog的最后边会有CRASH的关键字或者在我们的adblog中搜索fatal的关键字:

 

// CRASH: com.android.browser (pid 8766)
// Short Msg: java.lang.IllegalArgumentException
// Long Msg: java.lang.IllegalArgumentException: parameter must be a descendant
of this view
// Build Label:SR402/Q203/Q203_CCE:4.0.4/IMM76I/eng.pub1.20130703.094433:user/t
est-keys
// Build Changelist: eng.pub1.20130703.094433
// Build Time: 1372815912000
// java.lang.IllegalArgumentException: parameter must be a descendant of thisvi
ew
// at android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java
:4157)
// at android.view.ViewGroup.offsetRectIntoDescendantCoords(ViewGroup.java:
4100)
// at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:34
00)
// at android.view.ViewRootImpl.handleFinishedEvent(ViewRootImpl.java:3306)

// atandroid.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2466)
// at android.os.Handler.dispatchMessage(Handler.java:99)
// at android.os.Looper.loop(Looper.java:137)
// at android.app.ActivityThread.main(ActivityThread.java:4482)
// at java.lang.reflect.Method.invokeNative(Native Method)
// at java.lang.reflect.Method.invoke(Method.java:511)
// at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit
.java:787)
// at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
// at dalvik.system.NativeStart.main(Native Method)
//
app_crashcom.android.browser_2013-07-05_02_59_35.455_.txt:
// app_crashcom.android.browser_2013-07-05_02_59_35.455_.txt status was 0

 

Monkey aborted due to error.
Events injected: 74031
:Dropped: keys=73 pointers=1022 trackballs=0 flips=0

Network stats: elapsed time=1318105ms(859932ms mobile, 0ms wifi, 458173ms no
t connected)

System appears to have crashed at event 74031of 1000000 using seed 100

 

(2)monkey测试中出现无响应(anr)现象

下边是以前测试phone出现的anr现象,monkey log如下:

在monkeylog的最后边会有NOT RESPONDING的关键字:

 

 

Sleeping for 0 milliseconds

:Sending Touch (ACTION_DOWN): 0:(25.0,153.0)

// NOT RESPONDING: com.android.phone (pid 751)

act=ACTION_ENABLE_CHANNELS_GSMLoad: 12.93 / 13.27 / 12.31

CPU usage from 7183ms to 2144ms ago:

  57%1235/com.android.contacts: 51% user + 5.9% kernel / faults: 1229 minor

  32% 378/system_server:22% user + 9.5% kernel / faults: 228 minor

  13% 128/surfaceflinger:8.5% user + 4.7% kernel / faults: 20 minor

  9.9%734/com.android.inputmethod.latin: 8.3% user + 1.5% kernel / faults: 21 minor

  8.3% 2616/com.android.commands.monkey:6.5% user + 1.7% kernel / faults: 87 minor

  7.9% 2471/adbd: 2.3%user + 5.5% kernel

  4.3% 131/mediaserver:2.7% user + 1.5% kernel

  3.5%695/com.android.systemui: 3.3% user + 0.1% kernel / faults: 1082 minor

  2.3% 132/dbus-daemon: 2.3%user + 0% kernel

  1.3% 2650/logcat: 0.3%user + 0.9% kernel

  1.1% 6183/kworker/0:0:0% user + 1.1% kernel

  0.9% 1053/mpdecision: 0%user + 0.9% kernel

  0.7% 7790/kworker/u:3:0% user + 0.7% kernel

  0.5% 9141/kworker/1:1:0% user + 0.5% kernel

  0.3% 22/kworker/u:1: 0%user + 0.3% kernel

  0.3% 143/alljoyn-daemon:0.1% user + 0.1% kernel / faults: 27 minor

  0.1% 1//init: 0% user +0.1% kernel / faults: 35 minor

  0% 3/ksoftirqd/0: 0%user + 0% kernel

  0.1% 5/kworker/u:0: 0%user + 0.1% kernel

 +0% 9350/hciattach: 0%user + 0% kernel

 +0% 9352/irq/301-msm_hs_:0% user + 0% kernel

 +0% 9353/hci0: 0% user +0% kernel

 +0% 9354/bluetoothd: 0%user + 0% kernel

 +0% 9375/dun-server: 0%user + 0% kernel

 +0% 9377/sapd: 0% user +0% kernel

 +0% 9400/abtfilt: 0% user+ 0% kernel

81% TOTAL: 57% user + 19% kernel + 5% iowait + 0.1% softirq

CPU usage from 928ms to 1470ms later:

  68%1235/com.android.contacts: 62% user + 5.5% kernel / faults: 84 minor

    62%1235/ndroid.contacts: 57% user + 5.5% kernel

    1.8% 5072/BinderThread #: 1.8% user + 0% kernel

    1.8% 6217/BinderThread #: 1.8% user + 0% kernel

  24% 378/system_server:14% user + 9.2% kernel / faults: 13 minor

    5.5%401/ActivityManager: 3.7% user + 1.8% kernel

    5.5% 460/InputDispatcher:1.8% user + 3.7% kernel

    1.8%378/system_server: 1.8% user + 0% kernel

    1.8%449/PowerManagerSer: 1.8% user + 0% kernel

    1.8% 789/Binder Thread#: 1.8% user + 0% kernel

    1.8% 810/Binder Thread#: 1.8% user + 0% kernel

    1.8% 811/Binder Thread#: 0% user + 1.8% kernel

    1.8% 814/Binder Thread#: 1.8% user + 0% kernel

    1.8% 1341/BinderThread #: 1.8% user + 0% kernel

  16%734/com.android.inputmethod.latin: 11% user + 5.5% kernel / faults: 5 minor

    7.4% 734/putmethod.latin:5.5% user + 1.8% kernel

    1.8% 747/Binder Thread#: 0% user + 1.8% kernel

    1.8% 749/Binder Thread#: 0% user + 1.8% kernel

    1.8% 2653/BinderThread #: 1.8% user + 0% kernel

  7.4% 128/surfaceflinger:5.5% user + 1.8% kernel / faults: 1 minor

    3.7%276/SurfaceFlinger: 3.7% user + 0% kernel

  7.2%2616/com.android.commands.monkey: 5.4% user + 1.8% kernel / faults: 12 minor

    7.2%2616/commands.monkey: 5.4% user + 1.8% kernel

  5.4% 2471/adbd: 0% user+ 5.4% kernel

    3.6% 2471/adbd: 0%user + 3.6% kernel

    1.8% 2473/adbd: 0%user + 1.8% kernel

  3.7% 131/mediaserver:1.8% user + 1.8% kernel

    1.8%9268/TimedEventQueue: 1.8% user + 0% kernel

  0.7% 5/kworker/u:0: 0%user + 0.7% kernel

  0.9%695/com.android.systemui: 0.9% user + 0% kernel

  1% 1053/mpdecision: 0%user + 1% kernel

    1% 1063/mpdecision: 0%user + 1% kernel

  1.2% 9141/kworker/1:1:0% user + 1.2% kernel

71% TOTAL: 50% user + 18% kernel + 1.8% iowait

 

 

procrank:

// Exception from procrank:

java.io.IOException: Error running exec(). Command: [procrank]Working Directory: null Environment: null

anr_com.android.phone_2013-07-05_04_02_24.737_.txt:

    // Rejecting start ofIntent { cmp=com.android.stk/.StkDialogActivity } in package com.android.stk

// anr_com.android.phone_2013-07-05_04_02_24.737_.txt status was0

anr traces:

// anr traces status was 0

meminfo:

// meminfo status was 0

** Monkey aborted due to error.

Events injected: 94581

:Dropped: keys=57 pointers=906 trackballs=0 flips=0

## Network stats: elapsed time=1891513ms (807371ms mobile, 0mswifi, 1084142ms not connected)

** System appears to have crashed at event 94581 of 1000000using seed 100

(3)monkey测试中uncaught exception停止。

 

11-01 08:53:27.113:ERROR/AndroidRuntime(1973):Uncaught handler: thread main exiting due to uncaught exception

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):java.lang.NullPointerException

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atandroid.widget.TabHost.dispatchKeyEvent(TabHost.java:279)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atandroid.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:748)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atandroid.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:748)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atandroid.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:748)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atandroid.widget.TabHost.dispatchKeyEvent(TabHost.java:275)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atandroid.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:748)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atandroid.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:748)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:748)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atcom.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1655)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atcom.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1102)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atandroid.app.Activity.dispatchKeyEvent(Activity.java:2038)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atcom.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1631)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atandroid.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2368)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atandroid.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2338)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atandroid.view.ViewRoot.handleMessage(ViewRoot.java:1641)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atandroid.os.Handler.dispatchMessage(Handler.java:99)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     at android.os.Looper.loop(Looper.java:123)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atandroid.app.ActivityThread.main(ActivityThread.java:4363)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atjava.lang.reflect.Method.invokeNative(Native Method)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atjava.lang.reflect.Method.invoke(Method.java:521)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     atcom.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

11-01 08:53:27.133: ERROR/AndroidRuntime(1973):     at dalvik.system.NativeStart.main(NativeMethod)

11-01 08:53:27.163: INFO/Process(53): Sending signal. PID: 1973SIG: 3

11-01 08:53:27.173: INFO/dalvikvm(1973): threadid=7: reacting tosignal 3

11-01 08:53:27.173: ERROR/dalvikvm(1973): Unable to open stacktrace file '/data/anr/traces.txt': Permission denied

11-01 08:53:27.622: INFO/AndroidRuntime(2077): AndroidRuntimeonExit calling exit(190)

11-01 08:53:33.702: WARN/ActivityManager(53): Launch timeout hasexpired, giving up wake lock!

11-01 08:53:33.733: WARN/ActivityManager(53): Activity idletimeout for HistoryRecord{43d3ab48 wfh.LessonTable/.MainTable}

11-01 08:53:41.173: DEBUG/dalvikvm(1334): GC freed 62 objects /3120 bytes in 2419ms

11-01 08:53:43.742: WARN/ActivityManager(53): Activity destroytimeout for HistoryRecord{43dc5028 wfh.LessonTable/.AWeekLesson}

 

(4)monkey异常停止,但在monkey log中没有有用log

 

对于这一类问题,我们首先要排查,手机的adb是否能连接上,是不是有人为的影响,手机是否处于开机状态,是否因为之前电量不足,而测试比较耗电的模块导致了手机低电量关机等。

下面的monkelog是在测试计算器时出现了异常停止,但是monkeylog没有直观的log信息(对于此类问题,研发可以通过log搜索到最后一个calendar_time关键字,,也就是monkey最后执行时间,并出现异常的时间在adblog中分析具体停止原因。)

 

//[calendar_time:2013-07-17 21:00:44.859 system_uptime:3960520]

  // Sending event #34700

:Sending Touch (ACTION_DOWN): 0:(225.0,1247.0)

:Sending Touch (ACTION_UP): 0:(316.6447,1145.2222)

:Sending Trackball (ACTION_MOVE): 0:(-3.0,-5.0)

:Sending Touch (ACTION_DOWN): 0:(504.0,372.0)

:Sending Trackball (ACTION_MOVE): 0:(-1.0,-2.0)

:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.android.calculator2/.Calculator;end

    // Allowing start ofIntent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]cmp=com.android.calculator2/.Calculator } in package com.android.calculator2

:Sending Touch (ACTION_DOWN): 0:(278.0,723.0)

:Sending Touch (ACTION_UP): 0:(209.08629,731.03766)

:Sending Touch (ACTION_DOWN): 0:(272.0,311.0)

:Sending Touch (ACTION_UP): 0:(269.88586,319.0354)

:Sending Trackball (ACTION_MOVE): 0:(4.0,1.0)

:Sending Touch (ACTION_DOWN): 0:(456.0,497.0)

//[calendar_time:2015-04-15 17:00:55.627system_uptime:3971287]

 // Sending event #34800

:Sending Touch (ACTION_UP): 0:(89.99596,759.6784)

 //activityResuming(com.android.launcher)

 // Rejecting resume ofpackage com.android.launcher

:Sending Flip keyboardOpen=false

 

六、Monkey log的简单分析

 

:Monkey: seed=0 count=800 因为没有指定seed的,所以这一块是随机的,count就是我们设置的事件数

:AllowPackage:com.android.contacts  这就是允许访问的package,也就是我们指定的

:IncludeCategory:android.intent.category.LAUNCHER:IncludeCategory:android.intent.category.MONKEY

// Selecting main activities fromcategory android.intent.category.LAUNCHER// 

+ Using main activitycom.android.contacts.activities.DialtactsActivity (from packagecom.android.contacts)//

+ Using main activitycom.android.contacts.activities.PeopleActivity (from packagecom.android.contacts)//

Selecting main activities fromcategory android.intent.category.MONKEY

 

// Seeded: 0

// Event percentages:

//  0: 15.0%       [--pct-touch PERCENT]调整触摸事件的百分比(触摸事件是一个down-up事件,它发生在屏幕的某一位置)

//  1: 10.0%       [--pct-motion PERCENT]调整动作事件的百分比

//  2: 15.0%       [--pct-trackballPERCENT]调整轨迹事件的百分比(轨迹事件由一个或几个随机的移动组成,有时还伴随有点击)。

//  3: 25.0%        [--pct-syskeys PERCENT]调整“系统”按键事件的百分比(如Home、Back、音量控制键等)。

//  4: 15.0%       [--pct-nav PERCENT]调整“基本”导航事件的百分比(导航事件由来自方向输入设备的up/down/left/right组成)。

//  5: 15.0%        [--pct-majornav PERCENT]调整“主要”导航事件的百分比(这些导航事件通常引发图形界面中的动作,如:回退按键、菜单按键)

//  6: 2.0%        [--pct-appswitchPERCENT]调整启动Activity的百分比。在随机间隔里,Monkey将执行一个startActivity()调用,作为最大程度覆盖包中全部Activity的一种方法。

//  7: 2.0%         [--pct-flip PERCENT]调整翻转事件百分比。

//  8: 1.0%        [--pct-anyeventPERCENT]调整其它类型事件的百分比。它包罗了所有其它类型的事件,如:按键、其它不常用的设备按钮等。

 

(下面表示表示跳转到com.android.contacts 里面的PeopleActivity这一个Activity里)

:Switch:#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;component=com.android.contacts/.activities.PeopleActivity;end 

// Allowing start of Intent {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]cmp=com.android.contacts/.activities.PeopleActivity } in packagecom.android.contacts

Sleeping for 200 milliseconds(这个就是我们设置的200ms的每两次事件的间隔)

(下面是发送的一些动作,如点击按下,点击放开,移动)

 

:Sending Key (ACTION_DOWN): 22    // KEYCODE_DPAD_RIGHT:Sending Key

(ACTION_UP): 22    // KEYCODE_DPAD_RIGHTSleeping

for 200 milliseconds:Sending Key(ACTION_DOWN)

: 23    // KEYCODE_DPAD_CENTER:Sending Key(ACTION_UP)

: 23    // KEYCODE_DPAD_CENTERSleeping for 200milliseconds:Sending Flip keyboardOpen=falseSleeping

for 200 milliseconds

:Sending Key (ACTION_DOWN): 20    // KEYCODE_DPAD_DOWN

:Sending Key (ACTION_UP): 20    // KEYCODE_DPAD_DOWN

Sleeping for 200 milliseconds

:Sending Touch (ACTION_DOWN):0:(313.0,367.0)

:Sending Touch (ACTION_UP):0:(313.19876,367.49512)

Sleeping for 200 milliseconds:SendingKey (ACTION_DOWN): 82  

// KEYCODE_MENU:Sending Key(ACTION_UP): 82   

// KEYCODE_MENUSleeping

for 200 milliseconds

:Sending Touch (ACTION_DOWN):0:(427.0,724.0)

:Sending Touch (ACTION_UP):0:(432.7109,722.9021)

Sleeping for 200 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)

Sleeping for 200 milliseconds

(下面是拒绝此跳转,因为它是跳转到非它自己的包的Activity,本测试中只是测试它程序所在的包,此跳转是跳出本程序,进入到settings的ManageAccountsSettingsActivity ) 

// Rejecting start of Intent {act=android.settings.SYNC_SETTINGScmp=com.android.settings/.Settings$ManageAccountsSettingsActivity } in packagecom.android.settings

:Sending Key (ACTION_DOWN): 21   // KEYCODE_DPAD_LEFT

:Sending Key (ACTION_UP): 21   // KEYCODE_DPAD_LEFTSleeping

for 200 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)

:SendingTrackball (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 200 milliseconds

:Sending Key (ACTION_DOWN): 130    // KEYCODE_MEDIA_RECORD

:Sending Key (ACTION_UP): 130    // KEYCODE_MEDIA_RECORDSleeping for 200milliseconds

(下面也是允许跳转,也就是允许跳转到测试包中的其他activity) 

// Allowing start of Intent {cmp=com.android.contacts/.preference.ContactsPreferenceActivity } in packagecom.android.contacts

: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.intent.category.HOME]cmp=com.android.launcher/com.android.launcher2.Launcher } in packagecom.android.launcher

:Sending Touch (ACTION_UP):0:(69.70096,174.86081)

Sleeping for 200 milliseconds

:Sending Key (ACTION_DOWN): 22    // KEYCODE_DPAD_RIGHT

:Sending Key (ACTION_UP): 22    // KEYCODE_DPAD_RIGHT

Sleeping for 200 milliseconds:SendingKey (ACTION_DOWN): 20    //KEYCODE_DPAD_DOWN

:Sending Key (ACTION_UP): 20    // KEYCODE_DPAD_DOWN

Sleeping for 200 milliseconds

:Sending Key (ACTION_DOWN): 82    // KEYCODE_MENU

:Sending Key (ACTION_UP): 82    // KEYCODE_MENU

Sleeping for 200 milliseconds

:Sending Touch (ACTION_DOWN):0:(21.0,468.0)

:Sending Touch (ACTION_POINTER_DOWN1): 0:(27.638153,474.00204) 1:(346.0,657.0)

:Sending Touch (ACTION_MOVE):0:(37.267162,481.8316) 1:(326.71375,662.1464)

:Sending Touch (ACTION_MOVE):0:(38.95241,487.67917) 1:(313.75757,666.34375)

:Sending Touch (ACTION_MOVE):0:(42.695473,490.5754) 1:(298.60742,671.7384)

:Sending Touch (ACTION_MOVE):0:(60.71522,499.6811) 1:(278.45618,674.3698)

:Sending Touch (ACTION_MOVE):0:(61.872463,509.58676) 1:(257.19217,681.1843)

:Sending Touch (ACTION_MOVE): 0:(75.17328,518.97986)1:(239.4733,684.1668)

:Sending Touch (ACTION_MOVE):0:(89.66536,529.8832) 1:(231.6301,692.0084)

:Sending Touch (ACTION_MOVE):0:(92.55939,532.7987) 1:(230.73659,694.44574)

:Sending Touch (ACTION_MOVE):0:(94.616165,533.37885) 1:(228.23737,701.20294)

:Sending Touch (ACTION_POINTER_UP 1):0:(94.91951,537.33026) 1:(207.84836,704.19226)

:Sending Touch (ACTION_UP):0:(103.09425,540.7762)

Events injected: 800

(下面是丢弃的,键=0,指针=0,轨迹球=0,翻转=0。 )

:Dropped: keys=0 pointers=8trackballs=0 flips=0

## Network stats: elapsedtime=47875ms (0ms mobile, 0ms wifi, 47875ms not connected) 

网络统计经过时间为47875ms,其中0ms是用于在手机数据的,0ms用于无线网络上,没有连接的时间为47875ms,意思就是一直没有连接上网络。

// Monkey finished(表明测试正常完成)

 

 

 

 

 


当前标题:Android之monkeyTest
浏览地址:http://myzitong.com/article/pdioii.html