Master Android Monkey: Essential Commands for Effective App Stress Testing
Learn how to use Android's Monkey command-line tool to generate pseudo‑random user events for stress testing, covering basic syntax, key parameters like -p, -v, --throttle, and --pct-touch, and how to interpret the output to identify crashes and performance issues.
Introduction
Monkey is a command‑line utility that generates pseudo‑random user event streams to stress‑test Android applications. It is powerful and flexible, allowing customized testing behavior through various options.
Basic Command Structure
The general syntax is: adb shell monkey [options] Here [options] represents configuration flags, and the command sends the specified number of events to the device.
Key Parameters
-p <package_name>: Target a specific app package. -v: Increase log verbosity; can be repeated. --throttle <ms>: Insert a fixed delay (in milliseconds) between events. --pct-touch <percent>: Set the percentage of touch events.
Example Commands
Send 500 random events to a particular app: adb shell monkey -p your.package.name 500 Send 500 events with verbose logging: adb shell monkey -p your.package.name -v 500 Send 500 events with a 300 ms throttle and verbose output:
adb shell monkey -p your.package.name --throttle 300 -v 500Send 500 events with 50 % touch events, a 300 ms throttle, and verbose output:
adb shell monkey -p your.package.name --pct-touch 50 --throttle 300 -v 500Running a Simple Test and Interpreting Output
Example: test com.example.myapp with 100 events, 80 % touch events, and a 300 ms throttle:
adb shell monkey -p com.example.myapp --pct-touch 80 --throttle 300 -v 100The command produces output such as:
:Sending Touch (ACTION_DOWN): 0
:Sending Touch (ACTION_UP): 0
:Sending Trackball (ACTION_MOVE): 0 : 0
:Sending Flip (ACTION_FLIP): 0
...
// Monkey finishedThis log shows each event type being sent and its target. If the application crashes or throws exceptions, Monkey records them, helping developers locate the problematic code.
Conclusion
After following this tutorial, you should be able to execute basic Monkey commands, combine parameters to suit different testing scenarios, and analyze the output to detect crashes. Future articles will explore additional event types supported by Monkey and strategies for optimizing test coverage.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
