How do you use monkey
and monkeyrunner
tools for android testing?
What are the basic commands needed?
Using Command Line Install the app first and then execute the below command in the command line. Install APK and Run the application in the device. Go to ../Android_Sdk/Platform-Tools directory. Execute command 'adb shell monkey -p yourpackageneme -v 1000 > app_log.
What is Monkey? Monkey is a command line tool that runs over ADB shell command line. It generates N number of random events such as random touches, gesture, system level events, etc. and sends to the system or app which you want to test.
Here are some useful tips when using monkey test.
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>
and use command like this:
adb shell monkey -p my.package -c android.intent.category.MONKEY -v 500
In Android 5.0+ you can use the feature Screen Pinning.
then run your monkey test.
Use the following command to stop monkey test:
adb shell ps | awk '/com\.android\.commands\.monkey/ { system("adb shell kill " $2) }'
monkey
and monkeyrunner
are different tools.
Monkey
You can run monkey
from adb shell
, then it will generate pseudo-random streams of user events. You can specify some conditions and constraints for the execution of these events (see documentation)
The basic syntax is:
$ adb shell monkey [options] <event-count>
Monkeyrunner
monkeyrunner
is an API to control an Android device or emulator from outside of Android code, as the documentation defines. You can basically write Python scripts that describes some actions to be executed on target device.
Sample Program
Quoting Android Developers documentation:
The monkeyrunner tool is not related to the UI/Application Exerciser Monkey, also known as the
monkey
tool. Themonkey
tool runs in anadb
shell directly on the device or emulator and generates pseudo-random streams of user and system events. In comparison, the monkeyrunner tool controls devices and emulators from a workstation by sending specific commands and events from an API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With