第二部分(實踐):html
準備:python
下載android sdk 地址:https://developer.android.com/index.htmlandroid
配置環境變量 (for Ubuntu or mac)shell
source /etc/profile app
下載安裝 python 2.7/3.6測試
一個app壓力測試實踐:spa
1. 準備一臺筆記本 和 一部android手機。手機開發者選項,打開usb鏈接htm
2. adb devices 查看設備事件
3. 安裝測試app。 adb install package.apk開發
4. 發送壓力指令: adb shell monkey 1000
5. 獲取app 包名: adb logcat | grep START 或者 adb logcat | findstr START
cmp= com.android.calculator2/.Calculator ' / ' 以前的部分就是包名
6. 指定包名 打壓力測試
adb shell monkey -p com.android.calculator2 1000
eg: 慕課app packagename = cn.com.open.mooc
Monkey 參數:
1. throttle 參數
adb shell monkey --throttle < milliseconds >
指定時間之間的時間間隔
2. seed 參數
指令隨機數的seed 值
adb shell monkey -s < seed > <envent-count>
adb shell monkey -p com.android.calculator2 -s 100 1000
3. 觸摸事件
設置觸摸事件的百分比
adb shell monkey --pct-touch < percent>
adb shell monkey -p com.android.calculator2 -s 100 --pct-touch 50 1000
4. 動做事件
指定動做事件百分比
adb shell monkey --pct-motion < percent > 這個事件的百分比 和 其餘事件的百分比 加起來 要等於100
eg: adb shell monkey -v -p com.android.calculator2 --pct-touch 50 --pct-motion 10 --pct-appswitch 40 1000
其中 touch事件 50%
motion事件 10%
appswitch事件 40%
一共隨機執行1000次
5. 其餘事件
軌跡球事件:adb shell monkey --pct-trackball < percent >
基本導航事件:adb shell monkey --pct-nav < percent >
主要導航事件: adb shell monkey --pct-majornav <percent >
系統導航事件 (Home鍵 BACK 撥號鍵 及音量鍵)adb shell monkey --pct-syskeys < percent >
啓動activity 事件(設定activity 的事件百分比): adb shell monkey -pct-appswitch < percent >
設定不經常使用事件 : adb shell monkey --pct-anyevent < percent >
6. 崩潰事件
忽略崩潰 和 異常
adb shell monkey --ignore-crashes < event-count >
7. 超時事件
ANR
adb shell monkey --ignore-timeouts < event-count >
ANR 存放路徑: adb shell -- cd /data/anr/ -- ls -- traces.text----excepton 信息分析log