this week began the automated testing of mobile input method Simeiji, while beginning to touch mobile browser automation testing. The next step is to do a monographic study of the Android automated test tools and methods.
The first article introduces the Monkey Test tool.
1 Automation Test background
Software testing is an important part of software product development process. Testing is of great significance for discovering defects in software and guaranteeing the quality of software. Statistics show that the time of software testing usually accounts for 40% of software development time, and some software with high reliability requirements is even more than 60%.
Manual testing and automated testing are two basic means of software testing, which complement each other and cannot be substituted for each other. Among them, the automated test can capture the resource conflict, multi-threading, deadlock and other manual testing difficult to find errors, can efficiently complete a large number of mechanical, repetitive testing, can simulate a large number of data or a large number of concurrent users and other applications, so as to effectively shorten the software testing cycle, improve the reliability and accuracy of testing.
2 What is Monkey
Monkey testing is one of the tools of Android automated testing, which simulates how long a device has been abnormal by simulating the user's key input, touch screen input, and so on. Monkey is a command-line tool that can be run on a simulator or in a real device, enabling stress testing of a system-wide or an application by sending a pseudo-random user event stream to the system.
The Monkey tool is very easy to use and you can test it by typing the Monkey command directly in the command window. The Monkey command has a lot of configuration options, for easy understanding of these commands, here first the command options are divided into four categories, followed by the introduction of the use of various command options, and then attached to the appendix the entire Monkey command options for easy access.
The Monkey command can be easily divided into the following four categories:
- Basic configuration options, such as setting the number of events attempted
- Run constraint options, such as setting test only for a single package
- Event type and frequency, such as how often a touch screen event is set
- debugging options, such as setting ignore application exceptions, continue sending events to the system until the count is complete
3 using Monkey for automated testing
The Monkey command tool can be used on both the emulator and the actual device. In this paper, we introduce the monkey test in the two environments respectively.
3.1 Using Monkey for automated testing on the simulator
3.1.1 Monkey commands the simplest usage
First, we introduce the simplest monkey command usage, which is used in the following format:
Monkey N
where n is an integer representing the number of times the pseudo-random event used for testing occurred.
As shown in 3.1, start the simulator. Then, under command-line window, enter the ADB shell command, shown in 3.2.
After you log in to the shell, you can use the Monkey command. The simplest use is to specify a number directly behind it, and the table
The number of events sent to the system, as shown in 3.3. Test results for simulator 3.4 are shown.
3.1.2 Constraint options for the specified test
The so-called test constraint option, which specifies that certain packages or classes of the system are tested by parameters, based on the specific test requirements. There are two main types of constraints: packages and classes.
(1) Specify the package for the test
If you need to test a specific application, you can specify a specific package name. Can be in the system directory/data/data
Find the corresponding package name below, 3.5.
After finding the corresponding package name, you can use the "-P" parameter to specify it when using Monkey, and also use "-V"
parameter specifies the feedback information in the test. Common formats are as follows:
Monkey–p Com.android.gallery–v 50
3.6 and 3.7 are command inputs and test procedures, respectively.
Note: You can specify only one package per "-P", or multiple "-p" parameters if you want to specify that multiple packages should be tested.
(2) class for the specified test
If you want to test a specific class, you can use the "-C" parameter to specify, if you want to specify more than one category, you need to specify with multiple "-C" parameter options, each "-C" can specify only one category. 3.1, it uses the command format
For:
Monkey–c Android.intent.category.launcher-v 50
Figure 3.8 and Figure 3.9 respectively for the specified class test command input and test process.
3.1.3 Specifying the event type and frequency of the test The Monkey command provides a number of options for specifying the type of event and frequency of occurrence, such as touch events, navigation events, track events (consisting of one or more random movements, sometimes accompanied by clicks). Sometimes in order to test a specific application, you need to pass the "event" repeated occurrence of special functional testing, you can use the monkey "-pct" option to specify the specific events and how often they occur. The command uses the following format example: Monkey--pct-syskeys 90 200 The above command indicates that the system key event rate is 90%, the total test 200 times, 3.10 and figure 3.11 are shown. Note: "pct" is preceded by two bars "--" in the English input state.
You can also specify how often two events occur, using the following command:
Monkey--pct-touch--pct-trackball 40 200 The above command indicates that the probability of a touch event and trajectory event is 50% and 40%, the total test 200 times, 3.12 and figure 3.13 are shown.
specifying the interval between events by "--throttle" can delay the occurrence of an event, as shown in 3.14 for a specified navigation event with a probability of 80%, with each event occurring 1 seconds apart, and a total of 200 tests. Tested as shown in 3.15.
3.1.4 Debugging options for specifying tests The Monkey command provides several debugging options for controlling the test process. For example, the parameter "--ignore-crashes", which ignores any exceptions that the application crashes or occurs, continues to send events to the system until the count is complete. Use the command format as follows: Monkey--ignore-crashes-v 5000 Figure 3.16 and Figure 3.17 Show the tests for the specified debug options and their test procedures, respectively.
3.2 Automated testing using Monkey on the Development Board The previous section focuses on testing with the Monkey Command tool on the emulator, listing several basic examples of command usage. In the actual equipment, it is also convenient to use the Monkey tool for application testing. To perform the monkey test on the actual device, you first need to start the Android system, and then let the device connect to the PC via the serial port and log in to the root of the Android system via SECURECRT on the PC. At this point, you can use the various commands described in the previous section to test your device automatically. Note that after logging into the root directory of the Android system, if you cannot find the monkey command, you should first run system/bin/sh to switch the bash environment. |
|
|
|
Reply Report |
|
|
|
4 Appendices 4.1 Command options for Monkey tools Usage:monkey [-P allowed_package [-P allowed_package] ...] [-C Main_category [-C main_category] ...] [--ignore-crashes] [--ignore-timeouts] [--ignore-security-exceptions] [--monitor-native-crashes] [--ignore-native-crashes] [--kill-process-after-error] [--hprof] [--pct-touch PERCENT] [--pct-motion PERCENT] [--pct-trackball PERCENT] [--pct-syskeys PERCENT] [--pct-nav PERCENT] [--pct-majornav PERCENT] [--pct-appswitch PERCENT] [--pct-flip PERCENT] [--pct-anyevent PERCENT] [--pkg-blacklist-file Package_blacklist_file] [--pkg-whitelist-file Package_whitelist_file] [--wait-dbg] [--dbg-no-events] [--setup ScriptFile] [-F ScriptFile [-f ScriptFile] ...] [--port Port] [-S SEED] [-V [-v] ...] [--throttle Millisec] [--randomize-throttle] [--profile-wait Millisec] [--device-sleep-time Millisec] [--randomize-script] [--script-log] [--bugreport] COUNT
4.2 Monkey Command Options Introduction <ignore_js_op>
<ignore_js_op> |
|
Android Automation Test Basics--monkey Test Tools (RPM)