Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Performing a Stress Test in Android Using Monkey Application Exerciser

DZone's Guide to

Performing a Stress Test in Android Using Monkey Application Exerciser

Monkey is the ultimate tool to help stress test your Android applications.

· Mobile Zone
Free Resource

Launching an app doesn’t need to be daunting. Whether you’re just getting started or need a refresher on mobile app testing best practices, this guide is your resource! Brought to you in partnership with Perfecto

The Monkey is a tool you run on your device to generate a random system level user events. It generates the specified number of events without any user interaction. This is generally helpful for performing stress test. This tool generates the random events from set of commands and collect the crashes or memory reports.

Note that this tool is not used for automation testing. This only helps to find the crashes that may not appear during regular use of application.

This tool uses Android Device Bridge ADB toolkit. To run this command you need to provide the application package name and total number of random events that you want to generate. The following command shows how to start monkey tool.

$  adb shell monkey -p com.javatechig.myapp 5000

When you run this test, you can watch your device or emulator. You will notice random events on UI elements are being generated. When the application crashes, it will stop the exerciser and prints the report on terminal window. The following screenshot depicts a crash report while testing my application.
Performing Stress Test in Android Using  Monkey Application Exerciser

There are a variety of ways to control the behavior of Monkey tool by passing different arguments. Let us go through some of the important ones.

You can see a complete list of all options by typing:

$  adb shell monkey --help

You must have noticed in the previous command, when the Monkey starts, it always starts the default application of the package specified. However in some cases your application may depend on some other third party apps such as device native camera to capture photo or integrating with Google Maps. For such cases, any event that launches something external will be dropped by default by Monkey tool.

This behavior can be controlled by providing an additional package -p argument to the Monkey command.

$  adb shell monkey -p com.javatechig.myapp -p com.google.map 5000

Now let us run the Monkey tool more intelligently by controlling the type of events that are triggered. For example if you want to ensure that 30 percent of the events are touch events, ypou need to specify the –pct-touch argument as follows.

$  adb shell monkey --pct-touch 30 -p com.javatechig.myapp 5000

Keep up with the latest DevTest Jargon with the latest Mobile DevTest Dictionary. Brought to you in partnership with Perfecto.

Topics:
android ,test

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}