Introduction to Android Monkey Testing: Steps, Log Analysis, and Automation
This article explains what Android Monkey testing is, walks through the preparation steps, command usage, log redirection, and basic Python-based log filtering, and suggests how to automate the process to improve mobile app stability before release.
Happy Weekends~
As product features grow, the need to optimize user experience and improve performance becomes urgent. Monkey, a well‑known tool for measuring software stability on Android, is introduced here with a concise overview.
Monkey Test Overview
Monkey is a command‑line utility that runs on an Android emulator or real device. It generates a stream of pseudo‑random user events (touches, drags, zooms, etc.) and records the target app’s state to perform stress testing. Its advantages are fast, effective stability testing without needing a PC; its drawback is the inability to weight events, leading to high randomness.
Typical Monkey Testing Steps
1. adb devices – Verify that the emulator or physical device is connected. This requires a properly set up Android SDK and environment variables.
2. Determine the package name of the app under test. After launching the app, run a command such as adb shell pm list packages | grep to obtain the package identifier.
3. Execute the Monkey command, for example: adb shell monkey -p com.example.app -v -v -v 1000 --throttle 500 --seed 12345 The command redirects its output to a custom file (e.g., ex_path.txt ). Using the same seed reproduces the exact event sequence, which is helpful for crash reproduction.
4. (Optional) Create a blacklist file ( blacklist.txt ) containing package names to exclude, or a whitelist to focus on specific apps.
Monkey Test Log Analysis
During testing, adb logcat can capture the device’s runtime logs. After the random event stream finishes, the ex_path.txt file can be examined for issues.
Key analysis steps include:
Search for keywords such as ANR , CRASH , or Exception to detect unresponsiveness, crashes, or other errors.
If an ANR is found, use adb pull /data/anr/traces.txt to retrieve the trace file for deeper investigation.
For crashes, combine the logcat output with the crash stack trace for detailed debugging.
The “Switch” field in Monkey logs indicates activity transitions; when an exception or crash appears, the Switch entry helps locate the problematic activity.
Simple Python Filtering Example
The article provides a basic Python script (shown in an image) that reads the Monkey output file and filters lines containing the above keywords, facilitating quick identification of problematic events.
Automation Suggestion
Monkey testing can be scheduled on a server via cron or other task schedulers to run at regular intervals. Adding automated log filtering, archiving error logs, and sending email notifications to the team further enhances product stability before launch.
Overall, Monkey testing is a lightweight yet powerful approach to uncover potential issues early in the mobile development lifecycle.
360 Quality & Efficiency
360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.
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.