Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

today I'm testing all app with:

$ adb shell monkey -p my.package -c android.intent.category.HOME -c android.intent.category.DEFAULT -v 500 -s "a random number"
like image 607
ademar111190 Avatar asked Apr 15 '13 15:04

ademar111190


People also ask

How do I use Monkeyrunner?

To provide a plugin to monkeyrunner, invoke the monkeyrunner command with the -plugin <plugin_jar> argument described in table 1. In your plugin code, you can import and extend the main monkeyrunner classes MonkeyDevice , MonkeyImage , and MonkeyRunner in com. android.

What is adb monkey?

The Monkey is a command-line tool that you can run on any emulator instance or on a device. It sends a pseudo-random stream of user events into the system, which acts as a stress test on the application software you are developing.

What is meant by monkey testing?

Definition: Monkey testing is a type of software testing in which a software or application is tested using random inputs with the sole purpose of trying and breaking the system. There are no rules in this type of testing. It completely works on the tester's mood or gut feeling and experience.


2 Answers

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 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"

save teste.py and run

$ monkeyrunner teste.py
like image 157
ademar111190 Avatar answered Sep 25 '22 03:09

ademar111190


This worked for me. Add category in manifest:

<activity android:name="MonkeyActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android: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
like image 35
Telmo Pimentel Mota Avatar answered Sep 25 '22 03:09

Telmo Pimentel Mota