我的包名为com.mywebsite.banana。
- 我想要一个种子,所以测试是可重复的:-s 13
- 我想有一个相当低的冗长级别:-v 我想运行 500
- 个伪随机命令:500
我这样称呼猴子:
adb shell monkey -s 13 -p com.mywebsite.banana -v 500
我的输出:
:Monkey: seed=13 count=500
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
No activities found to run, monkey aborted
我的AndroidManifest.xml里面有这个:
<categoy android:name="android.intent.category.LAUNCHER"/>
我做错了什么?在运行猴子之前,我需要向我的应用程序添加一些内容吗?主要活动位于com.mywebsite.banana - 这是要传入的正确路径,还是应该一直到这样的活动:com.mywebsite.banana.activityName?
从我所读到的内容来看,似乎我这样做是正确的:
- http://dnlkntt.wordpress.com/2014/04/01/how-to-stress-test-your-android-app-with-monkey/
- http://www.tutorialspoint.com/android/android_testing.htm
- http://hariniachala.blogspot.com/2011/09/android-application-ui-testing-with.html
编辑
尝试 1:
adb shell monkey -p com.mywebsite.banana -c intent.CATEGORY_LAUNCHER -v 500
结果 1:
:Monkey: seed=13 count=500
:AllowPackage: com.mywebsite.banana
:IncludeCategory: intent.CATEGORY_LAUNCHER
// Warning: no activities found for category intent.CATEGORY_LAUNCHER
** No activities found to run, monkey aborted
尝试 2:
adb shell monkey -p com.mywebsite.banana -c android.intent.category.MONKEY -v 500
结果 2:
:Monkey: seed=13 count=500
:AllowPackage: com.mywebsite.banana
:IncludeCategory: android.intent.category.MONKEY
No activities found to run, monkey aborted
尝试 3:
adb shell monkey -p com.mywebsite.banana -c android.intent.category.LAUNCHER -c android.intent.category.MONKEY -v 500
结果 3:
:Monkey: seed=13 count=500
:AllowPackage: com.mywebsite.banana
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
No activities found to run, monkey aborted
一些清单:
<activity
android:name="com.mywebsite.banana.FRCActivity"
android:launchMode="singleTask"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="none" />
<category android:name="android.intent.category.MONKEY"/>
</intent-filter>
</activity>
还尝试了此版本的清单,没有更改:
<activity
android:name="com.mywebsite.banana.FRCActivity"
android:launchMode="singleTask"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.MONKEY"/>
</intent-filter>
</activity>
好的!我想通了。显示的错误确实是正确的:
** No activities found to run, monkey aborted
这意味着我使用的包名称不正确。我盯着看了又盯着看,最后我的同事提到我们的构建系统会在将包推送到设备之前更改包的名称
因此,如果您收到此错误,请确保您确实知道包的名称是什么。
因此,最终有效的命令是这样的:
$ adb shell monkey -p com.mywebsite.banana.newname -v 5
顺便说一下,这个猴子命令的正确输出如下所示:
:Monkey: seed=1418671144561 count=5
:AllowPackage: com.mywebsite.banana.newname
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
// 0: 15.0%
// 1: 10.0%
// 2: 2.0%
// 3: 15.0%
// 4: -0.0%
// 5: 25.0%
// 6: 15.0%
// 7: 2.0%
// 8: 2.0%
// 9: 1.0%
// 10: 13.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.mywebsite.banana.newname/com.mywebsite.banana.MyActivity;end
// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.mywebsite.banana.newname/com.mywebsite.banana.MyActivity } in package com.mywebsite.banana.newname
Events injected: 5
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=175ms (0ms mobile, 0ms wifi, 175ms not connected)
// Monkey finished
最后一点:我不需要将android.intent.category.MONKEY
添加到我的AndroidManifest.xml文件中!
为了补充@ncrypticus的答案,我认为找出最终软件包名称的最简单方法是在模拟器上打开应用程序,然后在Android Studio中转到工具->布局检查器。这将显示该应用程序的包名称。
为了让我找到一个包的名称(它也被更改了),我试试这个:
$ adb shell monkey --ignore-crashes -c android.intent.category.LAUNCHER -v 10000 > text_logs.txt
它记录了很多意图,所有这些都指向介于两者之间的包名称也是我的。