前端时间一直在搞移动端的 UI 自动化回归测试,测试过程中发现 APP 的性能不是很好;问了一下领导才知道,公司目前并没有人在做 APP 性能测试,想自己尝试把性能这块实践起来,找出更多的 bug 来引起领导们对性能的重视。首先从简单的 Monkey 入手,在此抛砖引玉,望高手们多多指导。
参考资料:
思路
疑问:
此 APP 是需要登录的,测试过程中退出账号后无法再进入程序内部,不知道其他公司是如何避免的?
答:经咨询,目前常用两种做法:1. 让开发将退出按键给屏蔽掉 2.点击登录不检测账号和密码
针对不同 APP 都有什么策略还不是很清楚,比如延时、事件数量、事件比例 等设置成多少合适?
2. 运行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](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表中对比查看
![](/photo/2015/0679d74126b420f2a952e6eec6f322e6.png)
- 将记录的CPU数据插到Excel表中对比查看
![](/photo/2015/60191dfa6989d24a4f023f0e04d3b11f.png)
**暂时就这么多了,后期有什么没考虑到的再补上,欢迎大家来吐槽,请大神多多指导!!!**