Monkey for Android Testing

1. What is Monkey

Monkey is a command line tool in Android that can run in an emulator or on a real device. It sends a pseudo-random stream of user events (such as key input, touch screen input, gesture input, etc.) to the system to stress test the application under development. Monkey testing is a fast and effective way to test the stability and robustness of software.

Second, the characteristics of Monkey

1. The test object is only the application package, which has certain limitations.

2. The event stream data stream used in the Monky test is random and cannot be customized.

3. The object, event quantity, type, frequency, etc. of MonkeyTest can be set.

3. An example of Monkey test

Assuming that there is an Android device connected to the PC, the device under test is installed with the program under test, and the package name of the program under test is com.tencent.android.fortest, then:

Open CMD, cd to ..\android-sdk\platform-tools (if this directory has been added to the system path, this step can be omitted), enter the command adb shell monkey -p com.tencent.android.ForTest3 -v 50

It starts the specified application and sends 500 pseudo-random events to it. You can see that the fortest program starts, and there will be a lot of messy operations. The CMD control window will print a lot of logs until it ends.

Fourth, the detailed usage of Monkey

The basic syntax of Monkey is as follows:

$ adb shell monkey [options]

If options are not specified, Monkey will start in no-feedback mode and send events arbitrarily to all packages installed in the target environment. Here's a more typical command-line example that starts the specified application and sends it 500 pseudo-random events:

$ adb shell monkey -p com.google.android -v 500

Below is a list of all the options available on the Monkey command line.

--help

List simple usages.

-v

Each -v on the command line will increase the level of feedback information. Level 0 (the default) provides less information than startup prompts, test completion, and final results. Level 1 provides more detailed test information, such as events sent to Activity one by one. Level 2 provides more detailed setting information, such as the selected or unselected activities 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>

Insert a fixed delay between events. This option can slow down Monkey's execution speed. If this option is not specified, Monkey will not be delayed and events will be generated as quickly as possible.

--pct-touch <percent>

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

--pct-motion <percent>

Adjust the percentage of motion events (motion events consist of a down event somewhere on the screen, a series of pseudo-random events, and an up event).

--pct-trackball <percent>

Adjusts the percentage of track events (track events consist of one or several random moves, sometimes accompanied by clicks).

--pct-nav <percent>

Adjust the percentage of "basic" navigation events (navigation events consist of up/down/left/right from directional input devices).

--pct-majornav <percent>

Adjust the percentage of "primary" navigation events (these navigation events usually trigger actions in a GUI, such as: middle button, back button, menu button on a 5-way keyboard)

--pct-syskeys <percent>

Adjusts the percentage of "system" key events (these keys are usually reserved and used by the system, such as Home, Back, Start Call, End Call, and volume control keys).

--pct-appswitch <percent>

Adjust the percentage of startup Activity. At random intervals, Monkey will perform a startActivity() call as a way to maximize coverage of all activities in the package.

--pct-anyevent <percent>

Adjust the percentage for other types of events. It includes all other types of events, such as: key presses, other less commonly used device buttons, and so on.

Constraints

-p <allowed-package-name>

If one or several packages are specified with this parameter, Monkey will only allow the system to start activities in these packages. If your application also needs to access activities in other packages (such as selecting a contact), those packages also need to be specified here. If no package is specified, Monkey will allow the system to start activities in all packages. To specify multiple packages, you need to use multiple -p options, each -p option can only be used for one package.

-c <main-category>

If one or more categories are specified with this parameter, Monkey will only allow the system to start activities listed by one of these categories. If no category is specified, Monkey will choose activities listed in the following categories: Intent.CATEGORY_LAUNCHER or Intent.CATEGORY_MONKEY. To specify multiple categories, you need to use multiple -c options, each -c option can only be used for one category.

debugging

--dbg-no-events

With this option set, Monkey will perform an initial launch into a test Activity, and then no further events will be generated. For best results, combine it with -v, one or more package constraints, and a non-zero value that keeps Monkey running for 30 seconds or more, providing an environment where packages can be monitored by the application conversion between.

--hprof

Setting this option will generate profiling reports immediately before and after the Monkey event sequence. This will generate large files (~5Mb) in data/misc, so use it with care.

--ignore-crashes

Usually, when the application crashes or any runaway exception occurs, Monkey will stop functioning. If this option is set, Monkey will continue to send events to the system until the count is complete.

--ignore-timeouts

Normally, when the application has any timeout error (like the "Application Not Responding" dialog), Monkey will stop running. If this option is set, Monkey will continue to send events to the system until the count is complete.

--ignore-security-exceptions

Usually, when an application has a permission error (such as starting an Activity that requires certain permissions), 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

Normally, when Monkey stops due to an error, the application that failed will continue to run. When this option is set, the system will be notified to stop the process in which the error occurred. Note that a normal (successful) end does not stop the starting process, the device simply remains in the final state after the end event.

--monitor-native-crashes

Monitor and report crashes of native code in the Android system. If --kill-process-after-error is set, the system will stop running.

--wait-dbg

Stop the executing Monkey until a debugger is attached to it.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324974934&siteId=291194637