For automated tests on Android phones, monkey is much easier to use than CTS and Android unittest. It actually inherits a shell instruction from the ADB shell.
Monkey testing principles
The monkey test uses Socket Communication to simulate users' key input, touch screen input, and gesture input. When a monkey program is running on a simulator or device, if the user starts a system-level event, such as a click, touch, gesture, or system-level event, it generates a random pulse, therefore, you can use Monkey to load your software by random repetition.
Ii. Monkey program Introduction
1) The Monkey program is provided by the Android system and written in Java. The storage path in the android file system is/SDK/tools/lib/monkey. Jar. The corresponding path is as follows:
Note that my SDK is on the F drive
2) monkey. the jar program is started and executed by a shell script named "monkey". The storage path of the shell script in the android file system is/SDK/tools/bin/monkey;
In this way, you can perform the monkey test by executing: ADB shell monkey {+ command parameter} in the CMD window.
What if I don't use Monkey ???
Iii. Simple monkey Command help
To obtain the simple help provided by the monkey command, run the following command in cmd:
ADB shell monkey-help
In this way, there are various prompt command parameters.
I have introduced the parameters here.
1) parameter:-P
Parameter-P is used to restrict the use of this parameter to specify one or more packages (that is, Apps ). Specify
After the package, Monkey only allows the system to start the specified app. If no package is specified, monkey allows the system to start all apps on the device.
* Specify a package: ADB shell monkey-P com. example. sellclientapp 100
Note: COM. example. sellclientapp is the package name, and 100 is the event count (that is, let the monkey program simulate 100 random user events ).
* Specify multiple packages: ADB shell monkey-P com. HTC. Weather-P com.htc.pdf reader-P com. HTC. Photo. widgets 100:
* Package not specified: ADB shell monkey 100
Note: The Monkey randomly starts the app and sends 100 random events.
* To view all the packages on the device, run the following command in the CMD window:
> ADB Shell
# CD Data/Data
# Ls
My mobile phone does not have root, so this attribute cannot be used.
2) parameter:-V
This parameter is used to specify the level of feedback information (the information level is the log details), which is divided into three levels. The corresponding parameters are shown in the following table:
Log Level 0
Example ADB shell monkey-P com. HTC. Weather-V 100
It indicates the default value. Only the source code corresponding to the startup prompt, test completion, and final result is provided, which is very helpful for debugging.
Log Level 1
Example ADB shell monkey-P com. HTC. Weather-v 100
Provides detailed logs, including information about each event sent to the activity.
Log Level 2
Example ADB shell monkey-P com. HTC. Weather-v 100
Describe the most detailed logs, including the activity information selected or not in the test.
-S
Specifies the seed value of the pseudo-random number generator. If seed is the same, the event sequence generated by the two monkey tests is the same.
* Example:
Monkey Test 1: ADB shell monkey-P com. HTC. Weather-S 10 100
Monkey Test 2: ADB shell monkey-P com. HTC. Weather-S 10 100
The effects of the two tests are the same, because the simulated user operation sequence (each operation is composed of a series of operations in a certain sequence, that is, a sequence) is the same. Operation Sequence
Although columns are randomly generated, as long as we specify the same seed value, we can ensure that the random operation sequence generated by the two tests is identical, so this operation sequence is pseudo-
Host;
Monkey is very good and powerful. I have been experimenting with it and hope to be proved by the ox.
Study every day.