Android automated stress testing graphic tutorial-monkey Tool

Source: Internet
Author: User
Sometimes we need to perform stress tests on a software to check its performance. Manual testing is much less efficient and boring. At this time, a command line tool monkey in android can reduce a lot of repetitive and tedious work for us. The following describes the introduction, features, basic usage, test sample illustration, test stop conditions, and command parameters of the monkey tool.

1. What is the name of monkey? The monkey tool is a naughty monkey. It is used in the app to press, touch, roll, and jump. Monkey testing is a fast and effective method for automated testing on the Android platform, the monkey tool can simulate the touch screen, slide trackball, buttons, and other operations to test the stress of the software on the simulator or mobile phone device, and detect the stability and robustness of the software. It is used to send pseudo-random user event streams (such as key input, touch input, and gesture input) to the system to perform stress testing on the application being developed.

Ii. Features of monkey (1) the test object is only an application package (APK package) and has certain limitations. (2) The event stream data stream used for monkey testing is random, you cannot customize it. (3) You can set the monkeytest object, event quantity, type, and frequency. Although the monkey tool is not complete, it is enough to meet the basic test needs of the application. If you need more powerful testing tools, you can use the evolved monkeyrunner of monkey. If monkey is regarded as a Kindergarten Child, its evolutionary version of monkeyrunner can be regarded as a junior high school student. It supports custom plug-ins to control events at any time. In short, monkeyrunner can record and play back anything you can do on Simulators/devices. Monkeyrunner is not described here. For details, refer to its official documents or other relevant materials. Note: monkeyrunner official document URL

Http://developer.android.com/guide/developing/tools/monkeyrunner_concepts.html

III. Basic usage of monkey Syntax: $ ADB shell monkey [Options] If no options is specified, monkey will be started in non-feedback mode, and send any event to all packages installed in the target environment. The following is a more typical command line example. It starts a specified application and sends 1000 pseudo-random events to it: $ ADB shell monkey-p your. package. name-V Number $ monkey-P (package meaning) specifies the file name
-V (number and frequency of tests)
Number (times)

4. Diagram of the monkey test example a simple test example is used to get a preliminary understanding of and master the monkey test steps. Note that the ADB command is used for installation and related operations. The specific test procedure is as follows: (1) First, a test application (APK file) is prepared ). In order to test, a Guevara mobile phone ticket purchase app was selected for testing. Http://www.gewara.com/mobile/mobilemovie.xhtml. Download the APK file. Upload at, January 1

Download Attachment
(2.82 KB)

(2) copy the APK file to the platform-tools directory of the android SDK. For example, the author's SDK path is
D: \ Android-SDK-Windows \ platform-tools. Upload at, January 1

Download Attachment
(34.36 KB) (3) install the APK file (the premise is that it has been started and can detect the simulator ): if you have 91 assistants or peas installed, you can double-click the APK file to install them. You can also use the ADB command in Android to install them (as shown in, success indicates that the installation is successful ). The command for installing the APK file under the ADB command is: ADB
Install file name .apk. Upload at, January 1

Download Attachment
(21.38 KB) (4) after the application is installed, the startup icon of the application is displayed on the simulator and uploaded at, January 1 ,.

Download Attachment
(27.3 KB)

(5) After installing the APK file, you need to know the package name of the main activity (the first activity started) of the application. In this case, we can use ADB
The Shell Command finds the package name of the main activity of the program, as shown in. (With the APK package name known, we can also use the ADB command to uninstall the application; the command to uninstall the APK file is: ADB
Uninstall package name) Upload

Download Attachment
(33.37 KB) (6) Here is the most critical step. Use the moneky command for automated stress testing. Command: # Monkey-P com. gewara-V 1000 (parameter description:-P followed by the package name of the software,-V followed by the number of tests ). The software is tested automatically for 1000 times, which can be completed within several minutes. Upload at, January 1

Download Attachment
(7.46 KB)

Upload at, January 1

Download Attachment
(100.77 KB)

Upload at, January 1

Download Attachment
(88.95 KB)

Upload at, January 1

Download Attachment
(63.13 KB) Upload at pm

Download Attachment
(58.02 KB)

(7) after the test is completed, an error occurred in the program. Program errors indicate that the stability and robustness of the software need to be improved. In this case, you can open lotcat to view error information. Upload at, January 1

Download Attachment
(126.29 KB) 5. Stop Condition of the monkey test (1) if the first monkey runs on one or more specific packages, it will detect operations that attempt to switch to its package, and block it; (2) if the application crashes or receives any exceptions that are out of control, monkey will stop and report an error; (3) if the application generates an application not responding error, the monkey will stop and report an error. It is considered a stable and robust program through multiple monkey tests with different settings.

Vi. Monkey command parameters: as the test goes deeper, we need to ignore the app crash (the app crash will cause the monkey test to stop), instead of stopping. monkey can do the same. -- Ignore
Crashes can even generate a profiling report.
-- Hprof Note: Monkey specific parameter settings can be referred to: http://developer.android.com/guide/developing/tools/monkey.html through the parameter settings, you can complete more debugging functions, monkey command line parameters related to the description of Chinese see the table below.

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.