Skip to content Skip to sidebar Skip to footer

Android Monkey Test Choose A Specific Activity

I'm using the Android monkey test to test my android apps, it's works for my app, and is very cool. but I'd like to test an application activity in specific, how could i do that? t

Solution 1:

With Android monkey test i cannot test a specific activity, but with Android monkey runner i can do python scripts to simulate a monkey test, so i did a python script open the my activity and init the monkey test :)

#! /usr/bin/env monkeyrunnerfrom 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 testprint"start monkey test"for i inrange(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"

save teste.py and run

$ monkeyrunner teste.py

Solution 2:

This worked for me. Add category in manifest:

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

Where MonkeyActivity will perform an initialization setup for testing and from shell:

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

Solution 3:

From the docs:

-c If you specify one or more categories this way, the Monkey will only allow the system to visit activities that are listed with one of the specified categories. If you don't specify any categories, the Monkey will select activities listed with the category Intent.CATEGORY_LAUNCHER or Intent.CATEGORY_MONKEY. To specify multiple categories, use the -c option multiple times — one -c option per category.

so you remove the DEFAULT and LAUNCHER category from your command, add the MONKEY one to the activity you want to test in your manifest and the command is now simply:

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

Solution 4:

For me just worked with:

-c android.intent.category.LAUNCHER

according to my manifest standard category entry:

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

Post a Comment for "Android Monkey Test Choose A Specific Activity"