Android Stability Testing: SmartMonkey and Customizable Module-Level Monkey Tools
This article explains the importance of stability testing for mobile apps, compares the limitations of the native Android Monkey tool with the system‑level SmartMonkey and a customizable module‑level approach, and provides detailed configuration, usage commands, and environment setup instructions for enhanced UI traversal testing.
Stable product quality is essential for retaining users, making stability testing a mandatory part of mobile testing. This article introduces two widely used Baidu stability tools: the system‑level SmartMonkey and a customizable module‑level kernel stability tool.
The native Android Monkey tool generates random UI events to test long‑running operations, but it has several drawbacks: it can only target the whole system or a single app, cannot focus on specific modules or activities, and its randomness may miss critical user paths such as login flows required for payment operations.
To overcome these issues, a module‑level testing method is proposed. By configuring entry and exit activities, the test can stay within a specific module, ensuring continuous coverage of the targeted component.
Business‑oriented configuration
1. Support specific modules or activities : After each operation, the current screen is checked; if it matches the target activity, the test clicks the entry widget to return to the module.
2. Configure business actions and ratios : Business operations are written as automation scripts, abstracted into custom Monkey events, and their execution ratios can be set.
Usage methods
When running the Monkey command, additional parameters can be added:
sa package/activity/item – specifies the entry activity widget.
ea package/activity/item – specifies the exit activity widget to re‑enter the module when encountered.
m script_path --pct-custom – adds a custom business event with a defined execution ratio.
Example for testing the Baidu Browser:
Push browser_test.sh to /data/local/tmp/ (ensure it is executable).
Run: adb -d shell /data/local/tmp/monkey -s 0 -p packagename --throttle 2000 --pct-touch 15 --pct-nav 25 --pct-majornav 15 --pct-appswitch 2 --pct-anyevent 16 -a package/activity/itemname/[index] -v 100
The -a parameter defines the target activity and entry widget; the format is -a package/activity/itemname/[index] . The package/activity can be obtained via HierarchyViewer , and the index indicates which instance of the item to interact with when multiple identical items exist.
Tool environment configuration
To extend Monkey functionality, the original monkey.jar must be modified and recompiled. Steps include pushing the appropriate monkey.jar for the Android platform version to /data/local/tmp/monkey.jar and creating an executable /data/local/tmp/monkey script:
base=/data/local/tmp
export CLASSPATH=$base/monkey.jar
trap "" HUP
exec app_process/system/bin com.android.commands.monkey.Monkey $*After granting execution permission to the script, the extended Monkey command can be used as shown above.
Usage notes
For security reasons, the -a extension works only when system properties ro.secure=0 and ro.debuggable=1 are set, which typically requires a rooted device and modification of boot.img .
Overall, by customizing Monkey parameters and integrating business scripts, developers can achieve more precise, module‑focused stability testing for Android applications.
Baidu Intelligent Testing
Welcome to follow.
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.