[Android tool] Monkey tool (Automated stress testing)

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. Introduction to monkey

What is the monkey name? 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), which has certain limitations;

(2) The event stream data stream used for monkey testing is random and cannot be customized;

(3) You can set the object, event quantity, type, and frequency of monkeytest.

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

The basic syntax is as follows:

$ ADB shell monkey [Options]

If no options is specified, monkey starts in non-feedback mode and sends 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 of tests and frequency) number (number of times)

 

4. Diagram of monkey test examples

Through simple test examples, you can get a preliminary understanding of the monkey test steps. Note that the ADB command is used for installation and related operations. The test procedure is as follows:

(1) first, prepare an application for testing (APK file ). 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.

(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.

(3) install the APK file (the premise is that the simulator has been started and can be detected): users who have 91 assistants or peas installed can directly double-click the APK file for installation; you can also use the ADB command in Android to install the SDK (as shown in, success indicates that the SDK is successfully installed ). The command for installing the APK file under the ADB command is: ADB Install file name .apk.

(4) After installation, the startup icon of the application is displayed on the simulator.

(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 the ADB shell command to find the package name of the main activity of the program, as shown in. (If we know the package name of the APK, we can also use the ADB command to uninstall the application; the command to uninstall the APK file is: ADB uninstall package name)

(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.

 

(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.

 

5. Stop conditions for monkey testing

(1) If monkey runs on one or more specific packages first, it will detect and block operations that attempt to switch to its packages;

(2) If the application crashes or receives any exceptions that are out of control, the 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 parameter description

As the test goes deeper, we need to ignore the crash of the APP (the crash of the app will lead to the stop of the monkey test), instead of stopping, the monkey can do the same. -- Ignore crashes

It can even generate a profiling report. -- Hprof

Note: For specific monkey parameter settings, refer:

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

You can complete more debugging functions by setting parameters. The following table describes the Chinese parameters of the monkey command line.

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.