Android Monkey self-initiated test

Source: Internet
Author: User

The preface assumes that you do Android development, have not used monkey to test, then see this article today, hoping to solve some of your Android test problems. At least it will save you some time to test and find many other problems.
Monkey Simple Introduction Monkey is an android command line executable in the simulator and the actual device itself, it can simulate pseudo-random user event flow, such as Click, Touch, gesture and so on. You can use Monkey to stress test the program you are developing.
Characteristics of the Monkey:
    • The test object is the package name, specified by the-p parameter.
    • The stream of events used by the monkey test, the data flow is random, and cannot be defined by itself.

Monkey's use of monkey is the Android system comes with, the Java language written by their own proactive testing tool, the storage path in the Android file system is:/system/framework/monkey.jar
The Monkey.jar program is run by a shell script called "Monkey", where the shell script is stored on the Android file system:/system/bin/monkey
The basic syntax
adb shell Monkey [option] <event-count>

Number of references

[Option]-P

Use this parameter to specify a package or multiple packages (package, app) for constraint restrictions. Once specified, monkey only agrees that the system launches the specified app, assuming it is not specified, monkey will consent to the system launching all apps
[Option]-vUsed to specify the level of feedback information (the level of information is the exact extent of the log), which is divided into three levels, for example, as seen in the following:
Log levels: Level 0
Demo sample: adb shell monkey-p com.example.list-v 100
Description: Default value, provide only a small amount of information such as Startup prompt, test complete and finally result
Log levels: Level 1
Demo sample: adb shell monkey-p com.example.list-v-V 100
Description: Provides more specific log information, including event information sent to activity
Log levels: Level 2
Demo sample: adb shell monkey-p com.example.list-v-v-v 100
Description: Provides the most specific log information, including the selected and unchecked activity information in the test
[option]--kill-process-after-error
Description: Used to specify whether to stop execution of the current application error when it occurs. Assuming this parameter is specified, the application stops and remains in its current state when the user application error occurs
[option]--throttle <milliseconds>
Description: Used to specify the interval of time for the Monkey action event, in milliseconds
[option]--pct-trackball <percent>
Description: Adjust the percentage of track events
[option]--pct-nav <percent>
Description: Adjust the percentage of basic navigation events
[option]--pct-majornav <percent>
Description: Adjust the percentage of primary navigation events (these navigation events usually trigger actions in the graphical interface, such as: 5-way keyboard, Fallback button, menu button)
[option]--pct-anyevent <percent>
Description: Adjust the percentage of other types of events
<event-count>
Description: Specifies the number of random events
Example record the monkey command I used most often, which is the combination of the above parameters:
adb shell monkey-p com.example.listview-v-v-v--kill-process-after-error--pct-trackball 0--pct-nav 0--pct-majornav 0--pct-anyevent 0--throttle 500000 >/mnt/sdcard/monkey.log 2 >&1 &
Self-motivated script to write a script for their own initiative to test, save each time to enter a large number of monkey command, code such as the following:
#!/bin/bashreport_dir=./reportdate_time= ' Date ' +%y%m%d ' #remove old report  Filesecho ' Remove old reporting files ... "If [-D $REPORT _dir]; Thenrm-r $REPORT _dirfi#mkdir for new report Filesecho ' report files would be ' stored in $REPORT _dir ' mkdir $REPORT _dir#run m OnKey on Phone Systemecho "Monkey is running" adb shell monkey-p com.example.listview-v-v-  v--kill-process-after-er Ror  --pct-trackball 0--pct-nav 0--pct-majornav 0--pct-anyevent 0--throttle > 500000 $REPORT _dir/monkey_$dat E_time.log#grep creash logecho "Catch crash log ..." Grep-a 10-h-R crash $REPORT _dir > $REPORT _dir/crash_$date_time.lo G


Android Monkey self-initiated test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.