Basic knowledge about Android 12: Android automated testing 01-monkey

Source: Internet
Author: User

This week, we started the simeiji automated test on the mobile phone input method and started the automated test on mobile browsers. Next, we will conduct a special study on Android automated testing tools and methods.

The first section describes the monkey testing tool.

1. Automated Testing Background
Software testing is an important part of software product development. Testing is of great significance for discovering defects in software and ensuring the quality of software. Statistics show that software testing usually takes up to 40% of software development time, and software with high reliability requirements is up to 60%.
Manual and automated testing are two basic methods of software testing. They complement each other and cannot be replaced by each other. Among them, automated testing can capture errors that are hard to find in manual tests such as resource conflicts, multithreading, and deadlocks, and can efficiently complete a large number of Mechanical and repetitive tests, it can simulate a large amount of data or a large number of concurrent users and other application scenarios, so as to effectively shorten the software test cycle and improve the test reliability and accuracy.

2. What is monkey?
Monkey testing is one of the automated Android testing methods. It simulates users' key input and touch screen input to test how long the device has encountered an exception. Monkey is a command line tool that can run on simulators or devices. By sending pseudo-random user event streams to the system, you can perform stress testing on the entire system or an application.
The monkey tool is easy to use. You can directly enter the monkey command in the Command window to test the tool. The monkey command has many configuration options. To facilitate understanding of these commands, the Command Options are divided into four categories. In the following sections, we will introduce the use of various command options, then, the entire monkey command option is attached to the appendix for easy reference.
The monkey command can be divided into the following four types:

  • Basic configuration options, such as setting the number of attempted events
  • Run constraint options, such as setting to test only one package
  • Event type and frequency, such as setting the frequency of touch screen events
  • Debugging options, such as setting to ignore application exceptions, continue to send events to the system until the count is complete
3. Use monkey for automated testing
The monkey command tool can be used on simulators and real devices. Here we will introduce the monkey test in both environments.
3.1 Automated Testing Using monkey on the simulator
3.1.1 The Monkey command is the simplest to use
Method
First, we will introduce the simplest monkey command usage in the following format:
Monkey n
N is an integer that indicates the number of times a pseudo-random event is used for testing.
Start the simulator, as shown in Figure 3.1. Then, enter the ADB shell command in the command line window, as shown in 3.2.
After logging on to the shell, you can use the monkey command. The simplest method is to specify a number directly after the table.
Shows the number of events sent to the system, as shown in Figure 3.3. Result 3.4 of the simulator test is shown. 3.1.2 specify constraints for testing
The so-called test constraint option is to test certain packages or classes of the system by specifying parameters based on specific test requirements. There are two types of constraints: Package and class.
(1) Specify the test package
To test a specific application, you can specify the package name. In the system directory/data/Data
The corresponding package name, as shown in Figure 3.5. After finding the corresponding package name, you can use the "-P" parameter to specify the monkey. You can also use "-V"
The parameter specifies the feedback in the test. The common format is as follows:
Monkey-P com. Android. Gallery-V 50
3.6 and 3.7 are the command input and test processes respectively. Note: Each "-P" can only specify one package. To test multiple packages, you must specify multiple "-P" parameters.
(2) Specify the test class
To test a specific class, you can use the "-c" parameter to specify multiple classes. If you need to specify multiple classes, you must specify multiple "-c" Parameter options, each "-c" can only specify one category. As shown in 3.1, the command format used
Is:
Monkey-C Android. Intent. Category. launcher-V 50
Figure 3.8 and Figure 3.9 respectively specify the class test command input and the test process. 3.1.3 specify the test event type and frequency 
The monkey command provides multiple options to specify the event type and frequency, such as touch events, navigation events, track events (composed of one or more random moves, click ). Sometimes, in order to test a specific application, special function tests need to be carried out through repeated "events, in this case, you can use the "-PCT" option of monkey to specify the specific event and its occurrence frequency. The command format is as follows:
Monkey -- PCT-syskeys 90 90 200
The preceding command indicates that the system button event rate is 90%, 200 tests performed in total, as shown in Figure 3.10 and 3.11.
Note: The front of "PCT" is the "--" command in the English input state. You can also specify the frequency of two events. The command is used as follows: monkey -- PCT-touch 50 -- PCT-trackball 40 200.
The preceding commands indicate that the probability of a touch event and a track event is 50% and 40%, respectively. A total of 200 tests are performed, as shown in Figure 3.12 and figure 3.13. You can use "-- throttle" to specify the interval between events to delay the occurrence of events. As shown in Figure 3.14, the probability of a specified navigation event is 80%. Each event occurs within one second, A total of 200 tests were performed. See Figure 3.15. 3.1.4 specify test debugging options
The monkey command provides several debugging options for controlling the test process. For example, the parameter "-- ignore-Crashes" will ignore application crashes or any exceptions, and send events to the system until the count is complete. The command format is as follows:
Monkey -- ignore-crashes-V 5000
Figure 3.16 and figure 3.17 respectively show the test with the specified debugging option and the test process. 3.2 automated testing using monkey on the Development Board 
The previous section describes how to use the monkey command tool to test on the simulator and lists some basic command examples. In actual devices, you can also use the monkey tool to conveniently test applications.
To perform a monkey test on the actual device, first start the Android system, connect the device to the PC through the serial port, and log on to the root directory of the Android system through securecrt on the PC. In this case, you can use the commands described in the previous section to perform automated testing on the device.
Note: After logging on to the root directory of the Android system, if the monkey command cannot be found, Run System/bin/sh to switch to the bash environment. 4 Appendix
4.1 Command Options of the monkey Tool
 
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-Reset witch 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 Introduction to monkey Command Options
References :【 A N D R O I D   M O N K E Y From Dynamic Test Try Work With Enable Use Report Notice ]

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.