MonkeyTest

1. 测试现状&MonkeyTest的局限性

一个Android apk开发出来之后,可以采用MonkeyTest进一步发现产品的一些缺陷。


事实上,MonkeyTest发现缺陷的有效性是非常低的,但这是一部分软件开发人员最喜欢的一种质量保证方法。我们往往会看到一些apk开发人员在整个开发过程中,甚至没有一个正规的测试用例。仅仅是开发出来,凭着大脑的、凭着感觉对apk进行一些有限的操作/测试,然后可能就是顶多monkeytest一下。仅此而已!


为什么偏好monkeytest呢?因为只需要一条简单的命令,就可以让adb去测试;等到出现异常,monkeytest自然会停下来,而且告诉你异常出现在什么地方。


通常情况下这种方法很不错。但如果一个组织中存在着很多应用,而每个应用的质量都无法预料,那么所预期的monkeytest往往无法达到预期的效果,因为monkeytest可能会在其他应用中挂掉,导致自己的应用根本无法正常测试。——MonkeyTest并不是仅仅运行你的应用!


尽管如此,本文还是对大家钟爱的Monkey Test做简单的介绍。


2. MonkeyTest的命令

2.1 惯用命令

通常的命令如下:

adb shell monkey -p com.flybing-bird.myapp -v 10000

即用-p选项指定目标应用程序,即package name; 最后再指定monkey test运行次数。


2.2 Usage

下面是正式的usage:

flying-bird@flyingbird:~/software/android/adt-bundle-linux-x86-20140321/sdk/platform-tools$ ./adb shell monkey -h
usage: monkey [-p ALLOWED_PACKAGE [-p ALLOWED_PACKAGE] ...]
              [-c MAIN_CATEGORY [-c MAIN_CATEGORY] ...]
              [--ignore-crashes] [--ignore-timeouts]
              [--ignore-security-exceptions]
              [--monitor-native-crashes] [--ignore-native-crashes]
              [--kill-process-after-error] [--hprof]
              [--pct-touch PERCENT] [--pct-motion PERCENT]
              [--pct-trackball PERCENT] [--pct-syskeys PERCENT]
              [--pct-nav PERCENT] [--pct-majornav PERCENT]
              [--pct-appswitch PERCENT] [--pct-flip PERCENT]
              [--pct-anyevent PERCENT]
              [--pkg-blacklist-file PACKAGE_BLACKLIST_FILE]
              [--pkg-whitelist-file PACKAGE_WHITELIST_FILE]
              [--wait-dbg] [--dbg-no-events]
              [--setup scriptfile] [-f scriptfile [-f scriptfile] ...]
              [--port port]
              [-s SEED] [-v [-v] ...]
              [--throttle MILLISEC] [--randomize-throttle]
              COUNT
flying-bird@flyingbird:~/software/android/adt-bundle-linux-x86-20140321/sdk/platform-tools$

2.3 示例

:Monkey: seed=0 count=5000
:AllowPackage: com.example.helloworld
: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.category.LAUNCHER;launchFlags=0x10000000;component=com.example.helloworld/.MainActivity;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.helloworld/.MainActivity } in package com.example.helloworld
:Sending Pointer ACTION_MOVE x=-4.0 y=2.0
:Sending Pointer ACTION_UP x=0.0 y=0.0
...................
:Sending Pointer ACTION_DOWN x=441.0 y=11.0
:Sending Pointer ACTION_UP x=441.0 y=11.0
Events injected: 5000
:Dropped: keys=1444 pointers=3511 trackballs=0 flips=0
## Network stats: elapsed time=15157ms (0ms mobile, 0ms wifi, 15157ms not connected)
// Monkey finished



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值