7

我正在使用Android 猴子测试来测试我的 android 应用程序,它适用于我的应用程序,并且非常酷。但我想具体测试一个应用程序活动,我该怎么做?

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

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

4 回答 4

8

使用Android 猴子测试我无法测试特定活动,但使用Android 猴子运行器我可以执行 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
于 2013-04-15T19:35:32.823 回答
7

这对我有用。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
于 2013-05-22T17:14:20.180 回答
2

从文档:

-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"
于 2013-04-15T15:57:59.403 回答
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>
于 2014-08-19T18:17:30.023 回答