[Android] Monkey Tool test method

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size: medium;"><strong>I. Definition of Monkey</strong></span><br>Discover what software testing tools are, This article mainly introduces Monkey Tools. Monkey testing is an automated test of the Android platform, through the monkey program to simulate the user touch screen, swipe, button and other operations to stress the program on the device, the detection of how long the program will be abnormal. The time interval for each operation is set by our testers by parameters, and usually we set the time interval for each operation to 500ms.</p></p><p><p>Monkey program Introduction:<br>The monkey program is powered by the Android system and is written in the Java language, where the path to the Android file system Is:/system/framework/monkey.jar</p></p><p><p></p></p><p><p>Note: the Monkey.jar program is initiated by a shell script called "Monkey", where the shell script is stored in the Android file system:/system/bin/monkey;<br>This allows the monkey to be tested by executing in the cmd window: adb shell Monkey {+ command arguments}.</p></p><p><p> <span style="font-size:medium;"> <strong> ii, Monkey Test </strong> </span> <br> <span style="background-color:rgb (204 , 255, 204); ">1, Monkey Test Preparation </span> <br> before performing the monkey test, we need to download the ADB tool and install the JDK v1.5 above Version. The <br> adb tool is a google-provided Android debugging tool that allows you to access your phone from the Linux command line. <br> Install the JDK environment, download adbtools, We need to configure the environment variables, the Adbtools storage path is added to the path, we can start the Monkey Test. <br> Note: Root permission is Required. <br> <span style="background-color:rgb (204, 255, 204);"> 2, execute monkey test </span> <br> Test command <br> "as we have learned above, Starting with the ADB command to perform the monkey test, the basic format of the Monkey command is: adb shell monkey–p com.android.xxx–v 180000––throttle 500. In this command,-p represents a package, which is the object we monkey test, a command can have multiple packages, each add a package requires a-p, such as adb shell Monkey–p package 1–p Package 2 .... Com.android.xxx is the object we need to perform the tests on, and the acquisition of the package name is detailed BELOW. The <br>-v represents the verbosity of the returned results, divided into 3 levels, level 1 levels, 2 and 3, the higher the rank, the more detailed the log returned, the 1-to-v, and the 2-level to the-v–v,3 level of –v–v–v. <br> 180000 represents the number of executions that are modified according to the actual test needs. The <br>-throttle 500 represents the interval, that is, the interval of time for each Operation. In order to better simulate user operations, you need to increase the interval between each operation, in milliseconds, and the meaning of this command is to increase the time interval of 500ms. </p></p><p><p><strong>Get the package name</strong><br>With the command to get the package name, adb shell ls/data/data, This command can display the package in the phone, and then find in the list of the packages that you need to test to Test.<br>If the phone memory has more packages, in the cmd window to view Inconvenient. You can export the package list as a TXT file and find information about packages: adb shell ls/data/data > D:\xxx.txt<br><br><span style="background-color: rgb(204, 255, 204);">3, Monkey Test Results analysis</span><br>After we get the log of the monkey test, we can use a few key words to determine whether the test Passed.<br>1) Monkey finished<br>Open log with notepad, and look at the bottom of the log, if there is a field similar to the following:<br># # Network stats:elapsed time=3799ms (3799ms mobile, 0ms wifi, 0ms not Connected)<br>Monkey finished<br>This field indicates that the monkey test passed, no exception<br>2) CRASH<br>similarly, after you get the log, search for the "CRASH" field, if the search results, it indicates that during the testing process, the test object error occurred, so the test failed.<br>CRASH:com.onekchi.downloadmanager (pid 12919)<br>3) Not Responding<br>Searching for the field in log, if there is a search result, indicates that the test object was unresponsive during the test, so the test failed.<br>4) Unable to search for the above information<br>This is usually the result of external reasons rather than the procedure Itself. such as the test process, the computer power off. Or the lack of memory during the test and so on, the result is obsolete, need to Re-test.</p></p><p><p><span style="font-size: medium;"><strong>three, Test Example</strong></span><br>The monkey test is performed on the download Butler and the test time is 10 Hours.<br>Test steps: 1, Mobile phone connected to the computer, through the adb shell ls/data/data View Download Butler specific package Name.</p></p><p><p>You can see the package name of the download butler as Follows: Com.onekchi.downloadmanager</p></p><p><p>then, at the command line, enter:<br>ADB Shell Monkey–p Com.onekchi.downloadmanager<br>–v–v–v 180000–throttle 500>d:\monkeytest.txt<br>This test begins with the end of the D drive found Monkeytest.txt opened and consulted, according to the results of the bill of Lading.</p></p><p><p><span style="font-size: medium;"><strong>Iv. Summary of monkey parameters</strong></span><br>1. parameters:-p<br>The parameter-p is used for constraint restrictions, and this parameter specifies one or more packages (the package, or app). Specified<br>After the package, monkey will only allow the system to launch the specified app. If you do not specify a package, monkey will allow the system to boot all apps in the Device.<br>* Specify a package: adb shell monkey-p com.htc.Weather 100<br>Description: Com.htc.Weather is the package name, 100 is the event Count (I.E. let the monkey program simulate 100 random user events).<br>* Specify multiple packages: adb shell monkey-p com.htc.weather–p com.htc.pdfreader-p com.htc.photo.widgets 100<br>* Do not specify package: adb shell Monkey 100<br>Description: Monkey randomly launches the app and sends 100 random EVENTS.<br>* To view all the packages in the device, execute the following command in the CMD window:<br>>ADB Shell<br>#cd Data/data<br>#ls</p></p><p><p>2. parameters:-v<br>Used to specify the level of feedback information (the level of information is the verbosity of the log), with a total of 3 levels, respectively, with the corresponding parameters as shown in the following table:<br>Log levels Level 0<br>Sample adb shell monkey-p com.htc.weather–v 100<br>Describe default values, providing only small amounts of information such as startup hints, test completion, and final results</p></p><p><p>Log levels Level 1<br>Sample adb shell monkey-p com.htc.weather–v-v 100<br>Description provides a more detailed log, including each event message sent to the activity</p></p><p><p>Log Levels Level 2<br>Sample adb shell monkey-p com.htc.weather–v-v–v 100<br>Description of the most detailed log, including the selected/unchecked activity information in the test</p></p><p><p>3. Parameter:-s<br>Used to specify the seed value of the pseudo-random number generator, and if the seed is the same, the sequence of events produced by the two monkey tests is the Same.<br>Example<br>Monkey test 1:adb Shell monkey-p com.htc.weather–s 10 100<br>Monkey test 2:adb Shell monkey-p com.htc.weather–s 10 100<br>The effect of the two Tests is the same, because the simulated sequence of user actions (a sequence of operations consisting of each operation in a certain order) is the Same. The sequence of operations is randomly generated, but as long as we specify the same seed value, we can guarantee that the random sequence of operations generated by the two tests is exactly the same, so this sequence of operations is pseudo-random;</p></p><p><p>4. Parameters:--throttle < MS ><br>Used to specify the delay between user actions (that is, events), in milliseconds;<br>* example: adb shell monkey-p com.htc.weather–throttle 3000 100</p></p><p><p>5. Parameters:--ignore-crashes<br>Lets you specify whether monkey stops running when the application crashes (force & Close error). If you use this parameter, even if the application crashes, monkey will still send the event until the event count is Complete.<br>* Example 1:ADB Shell monkey-p com.htc.Weather--ignore-crashes 1000<br>Even if the weather program crashes during the test, monkey continues to send events until the number of events reaches 1000;<br>* Example 2:ADB Shell monkey-p Com.htc.Weather 1000<br>During the test, if the weather program crashes, Monkey will stop running.</p></p><p><p>6. Parameters:--ignore-timeouts<br>Used to specify whether monkey stops running when an application has a ANR (application No Responding) Error. If you use this parameter, monkey will still send events until the event count is complete, even if the application has a ANR Error.</p></p><p><p>7. Parameters:--ignore-security-exceptions<br>Used to specify whether monkey stops running when an application has a licensing error (such as certificate licensing, network licensing, and so on). If you use this parameter, monkey will still send events until the event count is complete, even if the application has a licensing Error.</p></p><p><p>8. Parameters:--kill-process-after-error<br>Lets you specify whether to stop the application from running when an error occurs. If this parameter is specified, the application stops running and remains in the current state when an application error occurs (note: the application is only stationary in the state where the error occurred and the system does not end the Application's process).</p></p><p><p>9. Parameters:--monitor-native-crashes<br>Used to specify whether to monitor and report local code for application Crashes.</p></p><p><p>10. parameters:--pct-{+ Event category} {+ event category%}<br>Used to specify the percentage of events per category (in The Monkey event sequence, the number of such events as a percentage of the total number of events)</p></p><p><p>Parameters:<br>Instructions for Use:<br>Example:</p></p><p><p>--pct-touch {+ percent}<br>Adjust the percentage of touch events (touch event is a down-up event that occurs in a single location on the Screen)<br>ADB shell Monkey-p Com.htc.Weather--pct-touch 10 1000</p></p><p><p>--pct-motion {+ percent}<br>Adjust the percentage of Action events (an action event consists of a down event, a series of pseudo-random events, and an up event somewhere on the screen) adb shell monkey-p com.htc.Weather--pct-motion 20 1000</p></p><p><p>--pct-trackball {+ percent}<br>Adjusts the percentage of track events (track events consist of one or several random movements, sometimes accompanied by clicks)<br>ADB shell Monkey-p com.htc.Weather--pct-trackball 30 1000<br>--pct-nav {+ percent}</p></p><p><p>Adjust the percentage of basic navigation events (navigation events consist of up/down/left/right from the direction input Device)<br>ADB shell Monkey-p Com.htc.Weather--pct-nav 40 1000</p></p><p><p>--pct-majornav {+ percent}<br>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)<br>ADB shell Monkey-p Com.htc.Weather--pct-majornav 50 1000</p></p><p><p>--pct-syskeys {+ percent}<br>Adjust the percentage of the System key event (these keys are usually reserved for use by the system, such as home, back, Start call, End call, and volume control Keys)<br>ADB shell Monkey-p com.htc.Weather--pct-syskeys 60 1000</p></p><p><p>--pct-appswitch {+ percent}<br>Adjusts the percentage of startup Activity. In a random interval, monkey will execute a startactivity () call as a way to maximally cover all activity in the package<br>ADB shell Monkey-p com.htc.Weather--pct-appswitch 70 1000</p></p><p><p>--pct-anyevent {+ percent}<br>Adjusts the percentage of other types of events. It includes all other types of events, such as keystrokes, other infrequently used device buttons, and so On.<br>ADB Shell Monkey-p Com.htc.Weather</p></p><p><p>--pct-anyevent 100 1000* Specify the percentage of multiple types of events:<br>ADB shell Monkey-p com.htc.Weather--pct-anyevent--pct-appswitch 50 1000</p></p><p><p>Note: the total percentage of each event type cannot exceed 100%.</p></p><p><p></p></p><p><p>[Android] Monkey Tool test method</p></p></span>
Related Article

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.