Transferred from: http://blog.csdn.net/lfyx1357/article/details/7418133
Sometimes we need to stress test a software to check the performance of the software. If it is a manual test, the efficiency will be much lower, and will be more boring. At this point, a command-line tool in Android Monkey can alleviate a lot of repetitive and tedious work for us.
I. introduction of Monkey
and what does the name of Monkey come from? This did not go how fastidious,Monkey This tool is a naughty monkey, in the App, disorderly touch, roll, disorderly jump. Monkey testing is a fast and effective means of automated testing under the Android platform, with Monkey tools to simulate user touch screens, sliding trackball, Press the key to test the software on the simulator or mobile device, and check the stability and robustness of the software. Its principle is to send a pseudo-random user event stream (such as key input, touch input, gesture input, etc.) to the system for stress testing of the application under development.
Second, the characteristics of Monkey
(1) The test object is only the application package (apk package), has certain limitations;
(2)the event stream data stream used by the Monkey test is random and cannot be customized;
(3) The monkeytest object, the number of events, type, frequency, etc. can be set.
Although MonkeyThe tools are imperfect, but sufficient to meet the basic testing needs of the application. If you need a more powerful test tool, you can use theMonkeyThe evolutionary versionMonkeyrunner。 If you put as a kindergarten child, then its evolutionary version monkeyrunner, control event , at any time , Any of you in simulator /,monkeyrunner, and it can be recorded and played back. Here, the Monkeyrunner
Note:monkeyrunner Official document URL
http://developer.android.com/guide/developing/tools/monkeyrunner_concepts.html
Three, the basic usage of Monkey
The basic syntax is as follows:
$ adb shell monkey [options]
If you do not specify options,Monkey will start in a no-feedback mode and send events to all packages installed in the target environment. The following is a more typical command-line example that launches the specified application and sends a pseudo-random event to it:
$ adb shell monkey-p your.package.name-v number
$ monkey-p(package meaning) specify file name- v(number of tests and frequency )number (count)
Iv. Monkey Test example plots
Through a simple test example, the first step to understand and master the Monkey test. Note that this is mainly done by using the ADB command for installation and related operations. The specific reference steps for the test are as follows:
(1) First, a test application (apk file) is prepared first . To test this, a tile mobile phone ticket App is selected here to test. As: http://www.gewara.com/mobile/mobileMovie.xhtml.
After downloading, get the apk file as shown .
(2) Copy the apk file to the Android SDK corresponding to the Platform-tools directory. For example, the author's SDK path is D:\android\android-sdk-windows\platform-tools.
(3) Conductapk file installation (prerequisite is that the emulator has been started and can be detected): There is an installation 91< Span style= "font-family: the song Body;" > The user of the assistant or pea can directly double-click the apk files for installation; You can also use the Span style= "Font-family:times New Roman;" >androidadb command to install (as shown, successadb command to install apkadb install .apk
(4) once installed, you will see the application's Startup icon on the emulator
(5) install apk after file, you need to know the application master activityactivity command to find the program main activity The package name, we can also use adb command to uninstall the application, uninstall apkadb uninstall package name
(6) Here is the most critical step, using the moneky command for automated stress testing.
The command is: #monkey-P COM.GEWARA-V 1000 (parameter description: After-P followed by the package name of the software,-v followed by the number of tests). The software is automated and tested in a few minutes to complete the test.
(7) test completed, found that the program error. Program error indicates that the stability and robustness of the software has yet to be improved.
At this point, you can open Lotcat to view the error message.
Five, the Monkey test stop condition
(1) If the top Monkey is running on one or several specific packages, it detects and blocks the operation that is attempting to go to its package;
(2) If the application crashes or receives any runaway anomalies, theMonkey will stop and error;
(3) If the application produces an error that the application does not respondto (application not responding),Monkey will stop and make a mistake.
It is a program that is stable and robust enough to be tested by multiple and Monkey tests under different settings.
Vi..Monkey Command parameter description
As the test goes deeper, we need to ignore the app crash (thecrash of the app will cause the Monkey test to stop) instead of stopping,Monkey can do the same. --ignore crashes
Even, it can generate profiling reports. --hprof
Note:Monkey Specific parameters can be set for reference:
http://developer.android.com/guide/developing/tools/monkey.html
Through the parameter setting, can complete more debugging function,Monkey command line parameter Chinese related explanation see the following table.
Android Automated Stress test illustration tutorial--monkey Tools