monkey test method and command

1. Query test package information

# 查看已连接设备
adb devices 

# 带uuid查询包含test的第三方apk包
adb -s W21112003057 shell pm list package -3 | grep test 

# 清空logcat
adb -s W21112003057 logcat -c      

# 启动app,通过日志查看安装包信息
adb -s W21112003057 logcat |grep START   

  

2. money command

# help
adb shell monkey -help


# 指定包让Monkey程序模拟100次随机用户事件, 参数-p用于约束限制,用此参数指定一个或多个包(即App)。指定包之后,Monkey将只允许系统启动指定的APP;如果不指定包,Monkey将允许系统启动设备中的所有APP,com.sf.DarkCalculator为包名,100是事件计数。
adb shell monkey -p com.test.demo 100

# 日志级别用于指定反馈信息级别(信息级别就是日志的详细程度),Level 0为一个-v的命令,除了启动的提示、测试完成和最终结果之外,提供较少的信息 ;Level 1为两个-v的命令,提供较为详细的测试信息,如逐个发送到Activity的事件 ;Level 2为三个-v的命令,提供更加详细的测试信息,如测试中被选中或未被选中的Activity;
adb shell monkey -p com.test.demo –v 100

# --throttle <毫秒>用于指定用户操作(即事件)间的时延,单位是毫秒;如果不指定这个参数,monkey会尽可能快的生成和发送消息。
adb shell monkey -p com.test.demo –-throttle 1000 -v 100

# --pct-{+事件类别}{+事件类别百分比}用于指定每种类别事件的百分比(在Monkey事件序列中,该类事件数目占总事件数目的百分比),--pct-touch {+百分比}用于调整触摸事件的百分比(触摸事件是一个down-up事件,它发生在屏幕上的某单一位置)。
adb shell monkey -p com.test.demo --pct-touch 10 -v 1000

# 调整动作事件的百分比(动作事件由屏幕上某处的一个down事件、一系列的伪随机事件和一个up事件组成)。
adb shell monkey -p com.test.demo --pct-motion 20 -v 1000

# 调整轨迹事件的百分比(轨迹事件由一个或几个随机的移动组成,有时还伴随有点击)。
adb shell monkey -p com.test.demo --pct-trackball 30 -v 1000

# 调整“基本”导航事件的百分比(导航事件由来自方向输入设备的up/down/left/right组成)。
adb shell monkey -p com.test.demo --pct-nav 40 -v 1000
 

# 调整主要导航事件的百分比(这些导航事件通常引发图形界面中的动作,如:5-way键盘的中间按键、回退按键、菜单按键)。
adb shell monkey -p com.test.demo --pct-majornav 50 -v 1000

# 调整系统按键事件的百分比(这些按键通常被保留,由系统使用,如Home、Back、Start Call、End Call及音量控制键)
adb shell monkey -p com.test.demo --pct-syskeys 60 -v 1000

# 指定多个类型事件的百分比,各事件类型的百分比总数不能超过100%
adb shell monkey -p com.test.demo --pct-touch 50 --pct-motion 50 1000

# 即使app崩溃,Monkey依然继续发送事件,直到事件数目达到目标值为止
adb shell monkey -p com.test.demo  --ignore-crashes -v 1000
# 说明:用于指定当应用程序崩溃时(Force& Close错误),Monkey是否停止运行。如果使用--ignore-crashes参数,即使应用程序崩溃,Monkey依然会发送事件,直到事件计数达到1000为止。

# 即使APP发生ANR,Monkey依然继续发送事件,直到事件数目达到目标值为止
adb shell monkey -p com.test.demo --ignore-timeouts -v 1000
# 说明:用于指定当应用程序发生ANR(Application No Responding)错误时,Monkey是否停止运行如果使用--ignore-timeouts参数,即使应用程序发生ANR错误,Monkey依然会发送事件,直到事件计数完成。

 
# Monkey参数的约束限制规范:一个 -p 选项只能用于一个包,指定多个包,需要使用多个 -p 选项;-s <seed> 伪随机数生成器的seed值,如果用相同的seed值再次运行monkey,它将生成相同的事件序列,对9个事件分配相同的百分比;

3. Monkey Testing Suggestions

Interval time: 500 milliseconds;

number of seeds: random;

Encountered an error: do not stop;

Execution time: not less than 12 hours for each model or number of clicks: 1 million times;

Suggestions for model coverage: cover high-end, high-end and low-end models

Different chip platforms (Qualcomm, HiSilicon, MTK, etc.)

Different resolutions (mainstream resolution above 480*800)

Different Android versions (mainstream Android versions above Android 7.0);

4. Monkey reference command

adb shell monkey -p com.test.demo(替换包名) --throttle 500 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes -v -v -v 10000>monkey.log

常见命令组合:
1.monkey -p com.test.demo -v 500 :简单的输出测试的信息;
2.monkey -p com.test.demo -v -v -v 500  :以深度为三级输出测试信息;
3.monkey -p com.test.demo --port 端口号 -v :为测试分配一个专用的端口号,不过这个命令只能输出跳转的信息及有错误时输出信息;
4.monkey -p com.test.demo -s 数字 -v 500 :为随机数的事件序列定一个值,若出现问题下次可以重复同样的系列进行排错;
5.monkey -p com.test.demo -v --throttle 3000 500  :为每一次执行一次有效的事件后休眠3000毫秒;

5. Monkey log location

Android platform applications may have the following two problems: 1. Crash2, ANR (response delay)

Description of the main Log file

anr directory: logs exported from the mobile phone/data/anr, saving relevant information when anr crash occurs;

Troubleshooting steps through logs

Search the keywords "Fatal", "Crash", and "ANR" in the Monkey.log log file to locate the detailed stack information of the Crash, or analyze the log events before and after the Crash;

Guess you like

Origin blog.csdn.net/bulucc/article/details/130814316