Android Automated test tools

Source: Internet
Author: User

Recently completed the project, need to test, the pit father is the company recruit two months, have no test, so choose other path, found on the Internet a test method, that is, Monkey command line, through this command, select the application of the registration, you can imitate the click event, complete the test.

Android has a brief introduction to Monkey, and there are good translations on the web. This part directly refers to the original website and the translation of the Netizen.

The main command line is as follows:

ADB shell monkey-p cn.doolii.useng-v-V 10000 >f:\log.txt

This line of code means that the-p specifies that the package name of the test application, such as Cn.doolii.useng,-v, shows only the log level tested,-v-v-V is the highest level, and the log is the most detailed. -V 10000 refers to the automatic test 10,000 times, >f:\log.txt refers to the log in the format of the text output, that exists under the F disk. can be opened.

What is Monkey?


Monkey is a program that can run in the emulator or in the actual device. It sends pseudo-random user event streams (such as key input, touch input, gesture input, etc.) to the system, enabling stress testing of the application under development.
The Monkey is a program this runs on your emulator or device and generates pseudo-random streams of user events such as CL Icks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to Stress-test applications that is developing, in a random yet repeatable manner.

Monkey Introduction


Monkey is a command-line tool that can be run in the emulator or in the actual device. It sends a pseudo-random user event stream to the system, enabling stress testing of the application under development. Monkey includes many options, which are broadly divided into four categories:
· Basic configuration options, such as setting the number of events to try.
· Run constraint options, such as setting to test only a single package.
· The event type and frequency.
· Debugging options.
When the monkey is running, it generates events and sends them to the system. At the same time, monkey also monitors the system under test, and carries out special treatment for the following three cases:
· If Monkey is qualified to run on one or several specific packages, it will monitor and block attempts to move to other packages.
· If the application crashes or receives any runaway exceptions, the monkey will stop and error.
· If the application produces an error that the application does not respond to (application not responding), Monkey will stop and make a mistake.
According to the different levels of feedback you have selected, you can also see their execution process reports and generated events in monkey.
The Monkey is a command-line tool, that's, can run on any emulator instance or on a device. It sends a pseudo-random stream of the user events into the system, which acts as a stress test on the application software yo U are developing.
The Monkey includes a number of options, but they break-into-four primary categories
Basic configuration options, such as setting the number of events to attempt.
Operational constraints, such as restricting the test to a single package.
Event types and frequencies.
Debugging options.
When the Monkey runs, it generates events and sends them to the system. It also watches the system under test and looks for three conditions, which it treats specially
If you had constrained the Monkey to run in one or more specific packages, it watches-attempts to navigate-any oth Er packages, and blocks them.
If your application crashes or receives any sort of unhandled exception, the Monkey would stop and report the error.
If your application generates an application not responding error, the Monkey would stop and report the error.
Depending on the verbosity level you are selected, you'll also see reports on the progress of the Monkey and the events Being generated.


Basic usage of Monkey


You can start monkey by developing a command line or script on the machine. Because monkey is running in an emulator device environment, it must be started with the shell in its environment. You can do this by adding the ADB shell to each command, or you can enter the monkey command directly after entering the shell. 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 a specified application and sends 500 pseudo-random events to it:
$ adb shell Monkey-p your.package.name-v 500
You can launch the Monkey using a command line in your development machine or from a script. Because the Monkey runs in the Emulatordevice environment, you must launch it from a shell in that environment. You can do this by prefacing adb Shell to command, or by entering the shell and entering Monkey commands directly.
The basic syntax is
$ adb shell monkey [options] Event-count
With no options specified, the Monkey would launch in a quiet (non-verbose) mode, and would send events to any (and all) PAC Kages installed on your target. Typical command line, which would launch your application and send pseudo-random events to it
$ adb shell Monkey-p your.package.name-v 500


Command Options Reference


--help
Lists the simple usage.


-V
Each-V of the command line increases the level of feedback information. Level 0 (default) provides less information than startup prompts, test completion, and end results. Level 1 provides more detailed testing information, such as events sent individually to the activity. Level 2 provides more detailed setup information, such as the activity that was selected or unchecked in the test.


Event
-S seed
The seed value of the pseudo-random number generator. If you run monkey again with the same seed value, it will generate the same sequence of events.


--throttle milliseconds
Inserts a fixed delay between events. This option slows down the execution speed of the monkey. If this option is not specified, the monkey will not be delayed and the event will be produced as soon as possible.


--pct-touch percent
Adjusts the percentage of touch events (a touch event is a down-up event that occurs in a single location on the screen).


--pct-motion percent
Adjusts the percentage of action events (an action event consists of a down event, a series of pseudo-random events, and an up event somewhere on the screen).


--pct-trackball percent
Adjusts the percentage of track events (the trajectory event consists of one or more random movements, sometimes accompanied by clicks).


--pct-nav percent
Adjusts the percentage of the basic navigation event (the navigation event consists of the updownleftright from the direction input device).


--pct-majornav percent
Adjust the percentage of primary navigation events (these navigation events usually trigger actions in the graphical interface, such as: 5-way keyboard, Fallback button, menu button)


--pct-syskeys percent
Adjusts the percentage of the System key event (these keys are usually reserved for use by the system, such as home, back, Start call, End call, and volume control keys).


--pct-appswitch percent
Adjusts the percentage of startup activity. In a random interval, monkey executes a startactivity () call as a way to maximally cover all activity in the package.


--pct-anyevent percent
Adjusts the percentage of other types of events. It includes all other types of events, such as keystrokes, other infrequently used device buttons, and so on.


Constraint restrictions
-P Allowed-package-name
If you specify one or several packages with this parameter, monkey will only allow the system to start the activity in those packages. If your application also needs to access activity in other packages (such as choosing to take a contact), those packages need to be specified at the same time. If you do not specify any packages, monkey will allow the system to start the activity in all packages. To specify multiple packages, you need to use multiple-p options, and each-p option can be used for only one package.


-C Main-category
If you specify one or more categories with this parameter, monkey will only allow the system to start activity that is listed by a category in these categories. If you do not specify any categories, MONKEY will select the Activity:Intent.CATEGORY_LAUNCHER or Intent.category_monkey listed in the following categories. To specify multiple categories, you need to use multiple-c options, and each-c option can only be used for one category.


Debugging
--dbg-no-events
Set this option, monkey will perform the initial boot, enter into a test activity, and no further events will be generated. For best results, combine it with-V, one or several package constraints, and a non-0 value that keeps monkey running for 30 seconds or longer, providing an environment to monitor conversions between packages called by the application.


--hprof
Set this option to generate the profiling report immediately before and after the monkey event sequence. This will generate a large file (~5MB) in the Datamisc, so use it with care.


--ignore-crashes
Typically, monkey stops running when an application crashes or any runaway exception occurs. If this option is set, Monkey will continue to send events to the system until the count is complete.


--ignore-timeouts
Typically, monkey stops running when an application has any time-out errors, such as the application not responding dialog box. If this option is set, Monkey will continue to send events to the system until the count is complete.


--ignore-security-exceptions
Typically, when an application has a licensing error (such as starting an activity that requires some permission), Monkey will stop running. If this option is set, Monkey will continue to send events to the system until the count is complete.


--kill-process-after-error
Typically, when Monkey is stopped due to an error, the application that is faulted will continue to be in the running state. When this option is set, the system will be notified of the process of stopping the error. Note that the normal (successful) end, and does not stop the process from starting, the device simply stays in the final state after the end event.


--monitor-native-crashes
Monitor and report crash events for native code in your Android system. If--kill-process-after-error is set, the system will stop running.


--wait-dbg
Stop monkey in execution until there is a debugger connected to it.


In general, it is relatively simple to test with monkey, but it is necessary to do some more complex preparation work. The following is a detailed test procedure (very simple OH), the content is based on the already configured ADB environment (if this part is not clear, please first configure the environment, this does not describe).
1, ADB connected to Android test equipment.
2. Determine the PackageName of the application you want to test.
3. Use monkey to send a test command.

Detailed steps


The steps are really simple. The reader is not guaranteed to understand how to complete the above steps, and here is how to do each step.
1, ADB connected to Android test equipment.
If you're using an emulator, it's usually connected to the ADB after it's started. Both ways can be used for real machines:
One: use USB to connect the Android device to the PC and then install the driver (use pea pods if you are not looking for a driver).
Mode two: First of all make sure that your Android has successfully root, then you can use WiFi wireless connection. ① download a wifi adb app on your Android device; ② open wifi on Android adb;③ in the command line on the PC, enter the part of the WiFi adb display: ADB connect 192.168. x.x, the command line displays connected 192.168.x.x so the connection is OK.
I prefer the way two, so that you do not have to download the driver (mainly driven a lot of instability), and do not hurt the battery. Long time plugging on the USB is always bad for the battery. Just this way the device may need to be re-connected once it sleeps.
2. Determine the PackageName of the application you want to test.
First of all, the method described here is generic, and other methods on the net to get PackageName is not universal (because he is based on root, I do not guarantee that your device is root).
① on your Android device, click on the device you want to test, and then you don't have to operate the device.
② command Line input on PC: ADB logcatDlog.txt I

Here Dlog.txt you can change to other paths, but make sure you do not have this file in the path, otherwise your previous files have been changed, must be careful.
③ Press CTRL + C first to stop (to avoid excessive new information). Open the file that you just Dlog.txt. From the bottom of the file, look for information in the following format
Iactivitymanager (digital) Displayed Package name Class name + digital ms
For example, my information is as follows:

Iactivitymanager (272) Displayed Com.vane.act.ActLauncher +315ms
But you may find that there is a lot of information in this format, which is exactly what you need, and if you do it exactly as you just did, then it's probably the bottom piece of information, even if it's not so sure it's one of the next few messages, which requires you to identify it according to your application.
④ write down the package name you just got, the package named "Com.vane" in the example. It will be used immediately.
3. Use monkey to send a test command.
This step is relatively simple. command-line input directly on the PC: adb shell monkey-p com.vane-v 50
Note: The Com.vane in the above command is the package name obtained previously, the parameters in the command you can refer to the parameters in the above document to modify.
4. Observe the Android device until monkey stops.
5, if the application crashes, it is good to analyze the information in the monkey.

Android Automated test tools

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.