Monkey 随机脚本工具编写

Monkey 脚本生成工具架构


1、Monkey 脚本生成工具架构

问题导向,工具限制:

无法跳出测试应用,交互如何测试?
部分页面无法使用Monkey测试?
随意跳转页面,不受限制
脚本容易实现,简单快速
事件更多,比如长按
事件可定制调整,比如可以指定一些区域不点击
更容易测试交互影响
整机测试,交互更彻底

解决方案:使用Monkey脚本来生成随机事件流

Monkey 脚本的测试方面优势



Monkey异常结果


ANR输出异常格式:

System.err.println("// NOT RESPONDING:" + processName + " (pid " + pid + ")");

Crash输出异常格式:

扫描二维码关注公众号,回复: 2585242 查看本文章

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)




Monkey测试策略介绍


策略例子1:整机测试,而不测试拨号盘应用,忽略所有错误,次数100万次

adb shellmonkey -- ignore-crashes --ignore-timeouts -- pkg -blacklist-file/data/local/ tmp /blacklist.txt-v -v 1000000

策略例子2:测试计算器30万次,随机种子为100,随机延迟0-1秒,忽略所有错误

adb shell monkey  -pcom.android.calculator2  -s 100--throttle 1000 --randomize-throttle--ignore-crashes --ignore-timeouts -v -v 300000

策略例子3:测试计算器,触摸事件30%,其他按键50%,错误停止,延时200

adb shell monkey -p com.android.calculator2 --throttle 200 -- pct -touch30 -- pct-anyevent 50 -v -v 100000

策略例子4:对计算器进行旋转压力测试,事件延时2,10万次

adb shell monkey -p com.android.calculator2 -- pct -rotation 100 --throttle 2000100000

策略例子5:仅对整机的应用开启测试,事件延时5,10万次

adb shell monkey -- pct-appswitch 100 --throttle 5000 100000


猜你喜欢

转载自blog.csdn.net/qq_32639315/article/details/80821647
今日推荐