Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The old rookie takes you naughty: the Monkey test you never thought about!

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Monkey, that is, monkey, hin skin, so the Monkey test, as its name implies, is just like a monkey tapping buttons on the software to test. Monkeys don't know anything but press randomly. The principle of Monkey is similar, by sending pseudo-random streams of user events (such as key input, touch screen input, gesture input, etc.) to the system to test the application.

I'm sure most testers know about Monkey testing and even use it, but you may not dare to say how familiar you are with Monkey testing. It may seem simple, but how can we quickly get familiar with Monkey testing?

1. The basic methods of Monkey testing

Today, I want to simply share some of Android's Monkey tests. After a wave of testing, the Monkey test, as an auxiliary test, can still be used, simple and effortless.

Monkey is a command-line tool in Android that can be run in a simulator or in a real device. As long as you have adb installed, you are ready for Monkey testing.

Before doing Monkey testing, you need to install adb (the environment configuration of adb, there are many tutorials online, which are not described in detail here). Then connect the phone to the computer, open the menu, type "cmd" to open it, and enter the command line "adb devices" to determine whether the device is connected successfully. If the connection is successful, the device serial number will be displayed, as shown in the following figure.

Also, testers need to know the package name of the test app. You can get the package name by using the "uiautomatorviewer.bat" tool (described in a later article), or you can directly ask the developer who provided the app, or you can use the adb command to get the package name.

Briefly introduce one: get the package name through the adb command. First of all, you need to open the app in the phone that needs to get the package name. Then enter the commands separately. As shown in the following figure, the package name of the app is "com.screeclibinvoke".

1 、 adb shell

2. Dumpsys activity | grepmFocusedActivity

Then type a simple Monkey command to start the test.

Adb shell monkey-p com.screeclibinvoke 1000 (specifies an application with a package name of "com.screeclibinvoke" that randomly executes 1000 simulated events).

2. Common commands of Monkey

The parameters that can be used by Monkey are listed below.

Basic parameters

-- help print help documents

Each-v on the-v command line increases the level of feedback. Level 0 (also the default) has little information other 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 setup information, such as selected or unselected Activity in the test, for example adb shell-v-v 500

The seed of the pseudorandom generator. If the seed value is the same, then the resulting monkey event sequence is the same.

-- throttle adds a fixed time delay in milliseconds between events. If not, monkey will generate events as soon as possible

-- pct-touch adjusts the percentage of touch events (touch is a click event)

-- pct-motion adjusts the percentage of action events (action events refer to a down event, a series of random events, and then a up event)

-- pct-trackball adjusts the percentage of track events (track events consist of one or more movements, sometimes accompanied by click events)

-- pct-nav adjusts the percentage of basic navigation events (navigation events are arrow keys, up and down)

-- pct-majornav adjusts the percentage of major navigation events (these navigation events usually trigger actions in the graphical interface, such as the middle button of the 5-way keyboard, the back button, the menu button)

-- pct-syskeys adjusts the percentage of system keystroke events (these events are retained by the system, such as Home, Back, Start, Call, End Call and volume control keys)

-- pct-appswitch adjusts the percentage of startup activity. At random intervals, Monkey will execute a call to startActivity () as a way to maximize coverage of all Activity.

-- pct-anyevent adjusts the percentage of other types of events. Contains all other types of events, such as buttons, other rarely used device buttons, and so on.

Operation constraint

-p if one or more packages are specified with this parameter, monkey will only allow activity in those packages to be started. If your program needs to access another activity (such as the contact interface), you must also specify the contact's package, otherwise you can't access it. If you do not specify a package name, monkey will allow you to launch all packages installed on the phone. If you want to specify multiple packages, you need multiple-p options, each of which specifies a package.

"- c if one or more categories are specified with this parameter, Monkey will only allow the system to launch the Activity listed by one of these categories, and if no category is specified, Monkey will select the Activity listed in the following categories:"

Intent.CATEGORY_LAUNCHER or Intent.CATEGORY_MONKEY. To specify multiple categories, you need multiple-c options.

Debug option

-- dbg-no-event sets this option, and Monkey will perform the initial startup, enter a test Activity, and then no longer generate events. For best results, combine it with-v, one or more package constraints, and a non-zero value that keeps Monkey running events for 30 seconds or more, providing an environment in which you can monitor conversions between packages invoked by your application.

-- hprof sets this option to generate profiling reports immediately before and after the sequence of Monkey events. This will generate a large file (5m) in data/misc, so use it carefully.

-- ignore-crashes usually, when the tested app crashes or any runaway exception occurs, the Monkey will stop running. If you set this option, Monkey continues to send events to the system until the count is complete.

-- ignore-timeouts usually, when the program under test fails to respond, the Monkey stops running. If you set this option, Monkey continues to run until it is finished.

-- ignore-security-excuptions usually, when a permissible error occurs in the program under test, such as starting an Activity that requires authorization, the Monkey will stop running. If you set this option, Monkey will continue to run until it is finished.

-- kill-process-after-error usually, when Monkey stops running because of an error, the application that goes wrong will continue to run. If this option is set, the system will be notified to stop the process of sending errors. Note: the program ends normally and the program is not stopped. The device simply stays in its final state after the end of the event.

-- monitor-native-chrashes monitors and reports crashes of native code in the Android system. If-kill-process-after-error is set, the system will stop running.

-- wait-dbg stops executing Monkey until a debugger is connected to it.

III. An example of Monkey

I use the following command to do a wave of Monkey tests, and finally generate a.log log files on the computer's D disk.

Adb shell monkey-p com.screeclibinvoke-- throttle300-- ignore-crashes-- ignore-timeouts-- ignore-security-exceptions--ignore-native-crashes-- monitor-native-crashes-v-v-v 10000 > D:\ a.log

Program crashes (CRASH) and program unresponsiveness (ANR) may occur during Monkey testing. CRASH is the crash message, and the program exits abnormally while it is running. Set to ignore crashes and other conditions. After running the above command, search the generated log for the keyword "CRASH" or "NAR". You can locate the bug directly according to the log log and repair it, or complete the reproduction of bug according to the bug value.

Welcome to join the 51 software testing family, where you will get [latest industry information], [free test tool installation package], [software testing technology], [job interview skills]. 51 learn and grow with you! Looking forward to your joining: QQ Group: 755431660

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report