"Golden Sun Test" Android Automation-learning process: monkey principle and improved optimization

Source: Internet
Author: User

Chapter: Basic principles of automation--monkey and improved optimization (third speaking)

NetEase Cloud Classroom:

http://study.163.com/course/courseLearn.htm?courseId=712011#/learn/video?lessonId=878100&courseId=712011

Main content and notes:

First, theoretical knowledge:

Read the documentation directly to understand the concepts, fundamentals, and how to use monkey.

First,what is Android Monkey?

The Monkey is a program this runs on your emulator or device and generates pseudo-random streams of user events such as CL Icks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to Stress-test applications that is developing, in a random yet repeatable manner.

Translation: Monkey is a program that can run on a simulator or device, which can generate a pseudo-random sequence of user time, such as a click, touch screen, or crawl, and also contains a series of system-level events. We can use monkey to stress test our own applications, using random and repeatable operations.

Note: What are pseudo-random events?

The so-called pseudo-random event, that is: seed is the same, the random sequence does not change, and for a certain period of time, the generated random events are not duplicated.

Second,what can Monkey do?

The Monkey is a command-line tool, that's, can run on any emulator instance or on a device. It sends a pseudo-random stream of the user events into the system, which acts as a stress test on the application software yo U are developing.

The Monkey includes a number of options, but they break to into four primary categories:

    • Basic configuration options, such as setting the number of events to attempt.
    • Operational constraints, such as restricting the test to a single package.
    • Event types and frequencies.
    • Debugging options.

When the Monkey runs, it generates events and sends them to the system. It also watches the system under test and looks for three conditions, which it treats specially:

    • If you had constrained the Monkey to run in one or more specific packages, it watches-attempts to navigate-any oth Er packages, and blocks them.
    • If your application crashes or receives any sort of unhandled exception, the Monkey would stop and report the error.
    • If your application generates an application not responding error, the Monkey would stop and report the error.

Depending on the verbosity level you are selected, you'll also see reports on the progress of the Monkey and the events Being generated.

Translate here:

Monkey contains a variety of options, but they are divided into the following four basic sections:

    • Base setting options, such as setting the number of events to be done
    • Operational restrictions, such as restricting testing of a single package
    • Event Type and frequency
    • Debugging options

When monkey runs, it generates events and sends them to the system. It will also focus on the system under test, and note that the three cases will be treated in a special way:

    • If you limit the monkey to only one or more specific packages, it will focus on attempts to cross over to other packages and block them.
    • If your application collapses or accepts other types of uncontrolled anomalies, monkey will stop and report this error
    • If your application generates an app that doesn't send an error, Monkey will also block and report the error

Third,how to use Monkey?

The basic syntax is:

$ adb shell monkey [options] <event-count>

In general, we are relatively simple to use:

$ adb shell Monkey-p your.package.name-v 500

Next, focus on the meaning of the command line arguments:

Category Option Description
General --help Prints a simple usage guide.
-v Each-v on the command line would increment the verbosity level. Level 0 (the default) provides little information beyond startup notification, test completion, and final results. Level 1 provides more details on the test as it runs, such as individual events being sent to your activities. Level 2 provides + detailed setup information such as activities selected or not selected for testing.
Events -s <seed> Seed value for pseudo-random number generator. If you re-run the Monkey with the same seed value, it'll generate the same sequence of events.
--throttle <milliseconds> Inserts a fixed delay between events. You can use this option to slow down the Monkey. If not specified, there was no delay and the events are generated as rapidly as possible.
--pct-touch <percent> Adjust percentage of touch events. (Touch events is a down-up event in a and the screen.)
--pct-motion <percent> Adjust Percentage of motion events. (Motion events consist of a down event somewhere on the screens, a series of pseudo-random movements, and an up event.)
--pct-trackball <percent> Adjust percentage of trackball events. (Trackball events consist of one or more random movements, sometimes followed by a click.)
--pct-nav <percent> Adjust percentage of "basic" navigation events. (Navigation events consist of up/down/left/right, as input from a directional input device.)
--pct-majornav <percent> Adjust percentage of "major" navigation events. (These is navigation events that would typically cause actions within your UI, such as the center button in a 5-way pad, t He back key, or the menu key.)
--pct-syskeys <percent> Adjust percentage of "system" key events. (These is keys that is generally reserved for use by the system, such as Home, back, Start call, End call, or Volume con Trols.)
--pct-appswitch <percent> Adjust percentage of activity launches. At random intervals, the Monkey would issue a startactivity () call, as a-to-be-maximizing coverage of all activities Withi N your package.
--pct-anyevent <percent> Adjust percentage of other types of events. This was a catch-all for all other types of events such as keypresses, other less-used buttons on the device, and so forth.
Constraints -p <allowed-package-name> If you specify one or more packages this, the Monkey would only allow the system to visit activities within th OSE packages. If your application requires access to activities on other packages (e.g. to select a contact) you'll need to specify Thos e packages as well. If you don ' t specify any packages, the Monkey would allow the system to launch activities in all packages. To specify multiple packages, use the-p option multiple times-one-p option per package.
-c <main-category> If you specify one or more categories this, the Monkey would only allow the system to visit activities that AR E listed with one of the specified categories. If you don ' t specify any categories, the Monkey would select activities listed with the category Intent.category_launcher O R Intent.category_monkey. To specify multiple categories, use the-c option multiple times-one-c option per category.
Debugging --dbg-no-events When specified, the Monkey would perform the initial launch into a test activity, but would not be generate any further events. For best results, combine with-v, one or more package constraints, and a non-zero throttle to keep the Monkey running fo R seconds or more. This provides a environment in which the can monitor package transitions invoked by your application.
--hprof If set, this option would generate profiling reports immediately before and after the Monkey event sequence. This would generate large (~5MB) files in Data/misc. See Traceview For more information on trace files.
--ignore-crashes Normally, the Monkey would stop when the application crashes or experiences any type of unhandled exception. If you specify this option, the Monkey would continue to send events to the system, until the count is completed.
--ignore-timeouts Normally, the Monkey would stop when the application experiences any type of timeout error such as a ' application not RESPO Nding "dialog. If you specify this option, the Monkey would continue to send events to the system, until the count is completed.
--ignore-security-exceptions Normally, the Monkey would stop when the application experiences any type of permissions error, for example if it attempts To launch a activity that requires certain permissions. If you specify this option, the Monkey would continue to send events to the system, until the count is completed.
--kill-process-after-error Normally, when the Monkey stops due to a error, the application that failed would be a left running. When this option is set, it would signal the system to stop the process in which the error occurred. Note, under a normal (successful) completion, the launched process (es) is not stopped, and the device was simply left in T The He last state after the final event.
--monitor-native-crashes Watches for and reports crashes occurring in the Android system native code. If--kill-process-after-error is set, the system would stop.
--wait-dbg Stops the Monkey from executing until a debugger are attached to it.


Second, the basic principle of monkey architecture

Iii. Improved Monkey program 1 (click where you need to go): Do Java project, ADB push in

Iv. Optimizing Monkey Scheme 2 (out of ADB control): Make Android apk form, let system level process call it directly

"Golden Sun Test" Android Automation-learning process: monkey principle and improved optimization

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.