Android monkey test选择一个特定的活动

时间:2013-04-15 15:40:52

标签: android android-activity monkey-testing

我正在使用Android monkey test来测试我的Android应用,它适用于我的应用,非常酷。但是我想特定地测试一个应用程序活动,我该怎么做?

今天我正在测试所有应用:

$ adb shell monkey -p my.package -c android.intent.category.HOME -c android.intent.category.DEFAULT -v 500 -s "a random number"

4 个答案:

答案 0 :(得分:8)

使用Android monkey test我无法测试特定的活动,但使用Android monkey runner我可以使用python脚本来模拟猴子测试,所以我做了一个python脚本打开我的活动并启动猴子测试: )

#! /usr/bin/env monkeyrunner

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
from random import randint

print "get device"
device = MonkeyRunner.waitForConnection()
package = 'my.packaget'
activity = 'my.package.activity'
runComponent = package + '/' + activity
device.startActivity(component=runComponent)

#use commands like device.touch and device.drag to simulate a navigation and open my activity

#with your activity opened start your monkey test
print "start monkey test"
for i in range(1, 1000):
    #here i go emulate only simple touchs, but i can emulate swiper keyevents and more... :D
    device.touch(randint(0, 1000), randint(0, 800), 'DOWN_AND_UP')

print "end monkey test"

保存teste.py并运行

$ monkeyrunner teste.py

答案 1 :(得分:6)

这对我有用。在清单中添加category

<activity android:name="MonkeyActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.MONKEY" />
    </intent-filter>
</activity>

MonkeyActivity将执行测试和shell的初始化设置:

adb shell monkey -p my.package -c android.intent.category.MONKEY -v 500

答案 2 :(得分:1)

来自文档:

  

-c如果以这种方式指定一个或多个类别,Monkey将只允许系统访问列出的活动   与指定的类别之一。如果你没有指定任何   在类别中,Monkey将选择与该类别一起列出的活动   Intent.CATEGORY_LAUNCHER或Intent.CATEGORY_MONKEY。要指定   多个类别,多次使用-c选项 - 一个-c选项   每个类别。

所以你从你的命令中删除DEFAULT和LAUNCHER类别,将MONKEY一个添加到你要在清单中测试的活动,现在命令就是:

$ adb shell monkey -p my.package -c -v 500 -s "a random number"

答案 3 :(得分:1)

对我来说只是合作:

-c android.intent.category.LAUNCHER

根据我的标准类别条目:

<activity
                android:name="pl.com.infinitysoftware.carassistant.app.CarAssistantMainActivity"
                android:label="@string/app_name"
                android:launchMode="singleTask"
                android:configChanges="orientation|screenSize">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
</activity>
相关问题