问题导向,工具限制:
•无法跳出测试应用,交互如何测试?
•部分页面无法使用Monkey测试?
•随意跳转页面,不受限制
•脚本容易实现,简单快速
•事件更多,比如长按
•事件可定制调整,比如可以指定一些区域不点击
•更容易测试交互影响
•整机测试,交互更彻底
解决方案:使用Monkey脚本来生成随机事件流
Monkey 脚本的测试方面优势:
ANR输出异常格式:
System.err.println("// NOT RESPONDING:" + processName + " (pid " + pid + ")");
Crash输出异常格式:
System.err.println("// CRASH: " + processName + " (pid " + pid + ")");
System.err.println("// Short Msg: " + shortMsg);
System.err.println("// Long Msg: " + longMsg);
System.err.println("// Build Label: " +Build.FINGERPRINT);
System.err.println("// Build Changelist: " + Build.VERSION.INCREMENTAL);
System.err.println("// Build Time: " + Build.TIME);
System.err.println("// " + stackTrace.replace("\n", "\n// "));
ANR输出输出LOG:
// NOT RESPONDING: com.android.quicksearchbox (pid 6333)
ANR in com.android.quicksearchbox (com.android.quicksearchbox/.SearchActivity)
CPU usage from8381ms to 2276ms ago:
procrank: à adb shell procrank
anr traces: à保存于/data/anr/traces.txt
meminfo: àadb shell dumpsysmeminfo
Bugreport àadb bugreport 可选通过 --bugreport参数控制
CRASH输出输出LOG:
// CRASH: com.android.quicksearchbox (pid 1699)
// Short Msg: java.lang.NullPointerException
// Long Msg: java.lang.NullPointerException: Attempt to invokevirtual method 'com.android.quicksearchbox.SourceResultcom.android.quicksearchbox.Suggestions.getResult()' on a nullobject reference
// Build Label: generic/vbox86p/vbox86p:5.0/LRX21M/buildbot12160004:userdebug/test-keys
// Build Changelist: eng.buildbot.20141216.000103
// Build Time: 1418684697000
// java.lang.RuntimeException: Unable to stopactivity {com.android.quicksearchbox/com.android.quicksearchbox.SearchActivity}: java.lang.NullPointerException: Attempt to invokevirtual method 'com.android.quicksearchbox.SourceResultcom.android.quicksearchbox.Suggestions.getResult()' on a nullobject reference
// at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3344)
// at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3390)
// atandroid.app.ActivityThread.access$1100(ActivityThread.java:144)
// at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
// at android.os.Handler.dispatchMessage(Handler.java:102)
// at android.os.Looper.loop(Looper.java:135)
策略例子1:整机测试,而不测试拨号盘应用,忽略所有错误,次数100万次
策略例子2:测试计算器30万次,随机种子为100,随机延迟0-1秒,忽略所有错误
策略例子3:测试计算器,触摸事件30%,其他按键50%,错误停止,延时200
策略例子4:对计算器进行旋转压力测试,事件延时2秒,10万次
策略例子5:仅对整机的应用开启测试,事件延时5秒,10万次