参考资料:
1. Monkey测试策略:https://testerhome.com/topics/597
2. Android Monkey测试详细介绍:http://www.jikexueyuan.com/course/1619.html
3. Monkey总结:https://testerhome.com/topics/3517
测试步骤
思路
1. 目前做的是银行APP,另下载安装3个第三方手机银行的APP以方便对比
2. 将四个APP的包名添加到白名单,同时测试这四个APP
3. 运行Monkey,将日志记录到手机中
4. 测试过程中记录APP占用内存和CPU的变化
5. 测试完毕后查看Monkey日志,将内存和CPU数据用图表来分析。
疑问:
1. 此APP是需要登录的,测试过程中退出账号后无法再进入程序内部,不知道其他公司是如何避免的?
答:经咨询,目前常用两种做法:1. 让开发将退出按键给屏蔽掉 2.点击登录不检测账号和密码
- 针对不同APP都有什么策略还不是很清楚,比如延时、事件数量、事件比例 等设置成多少合适?
一、运行Monkey
- 将白名单push到手机
adb push E:\01_AutomationTest\01_Monkey\05_NbBank\whitelist.txt data/local/tmp/
- 运行Monkey
adb shell
monkey --pkg-whitelist-file /data/local/tmp/whitelist.txt --throttle 500 -s 100 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -v -v -v 15000 > /mnt/sdcard/monkey_test.txt &
根据sandman的建议,优化命令:
adb shell
monkey --pkg-whitelist-file /data/local/tmp/whitelist.txt --throttle 500 -s 100 --ignore-crashes --ignore-timeouts --ignore-security-exceptions --ignore-native-crashes --monitor-native-crashes -v -v -v 15000 1> /mnt/sdcard/monkey_test.txt 2>&1 &
2>&1的语法参考Linux的解释:http://blog.csdn.net/ithomer/article/details/9288353
二、内存检测
内存检测用批处理脚本记录,约5秒记录一次:
@echo off &color 0a&setlocal enabledelayedexpansion&title %~n0
::@mode con lines=18 cols=50
set package1=com.nbbank
set package2=cn.com.spdb.mobilebank.per
set package3=com.chinamworld.bocmbci
set package4=com.cmbchina.ccd.pluto.cmbActivity
adb shell dumpsys meminfo %package1% | findstr "Pss" > ./meminfo_1.txt
adb shell dumpsys meminfo %package1% | findstr "Pss" > ./meminfo_2.txt
adb shell dumpsys meminfo %package1% | findstr "Pss" > ./meminfo_3.txt
adb shell dumpsys meminfo %package1% | findstr "Pss" > ./meminfo_4.txt
:start
adb shell dumpsys meminfo %package1% | findstr "TOTAL" >> ./meminfo_1.txt
adb shell dumpsys meminfo %package2% | findstr "TOTAL" >> ./meminfo_2.txt
adb shell dumpsys meminfo %package3% | findstr "TOTAL" >> ./meminfo_3.txt
adb shell dumpsys meminfo %package4% | findstr "TOTAL" >> ./meminfo_4.txt
echo.
echo.
ping -n 5 127.1>nul
goto start
三、记录CPU百分比
@echo off &color 0a&setlocal enabledelayedexpansion&title %~n0
::@mode con lines=18 cols=50
set package1=com.nbbank
set package2=cn.com.spdb.mobilebank.per
set package3=com.chinamworld.bocmbci
set package4=com.cmbchina.ccd.pluto.cmbActivity
adb shell top -n 1 | findstr "PID" > ./cupInfo_1.txt
adb shell top -n 1 | findstr "PID" > ./cupInfo_2.txt
adb shell top -n 1 | findstr "PID" > ./cupInfo_3.txt
adb shell top -n 1 | findstr "PID" > ./cupInfo_4.txt
:start
adb shell top -n 1 | findstr %package1% >> ./cupInfo_1.txt
adb shell top -n 1 | findstr %package2% >> ./cupInfo_2.txt
adb shell top -n 1 | findstr %package3% >> ./cupInfo_3.txt
adb shell top -n 1 | findstr %package4% >> ./cupInfo_4.txt
echo.
echo.
ping -n 5 127.1>nul
goto start
注意:
命令adb shell top -n 1 | findstr %package1% 返回三行信息,暂未处理:
C:\Users\Stphen>adb shell top -n 1 | findstr com.nbbank
25353 0 1% S 23 543128K 66260K bg u0_a193 com.nbbank
25385 1 0% S 3 11480K 1368K fg u0_a193 com.nbbank
25383 0 0% S 3 11692K 4180K fg u0_a193 com.nbbank
四、结果分析
-
Crash、ANR、Force close暂时没发现,以后补上
-
将记录的内存数据插到Excel表中对比查看
- 将记录的CPU数据插到Excel表中对比查看