Highly recommended article: Welcome to collect Android dry goods to share

##### Read five minutes, 10 o ‘clock every day, and learn for life with you. This is Android programmer

Monkey testing is very common in development. This article will focus on Monkey testing. It mainly includes the following contents

  1. Monkey test command
  2. App Monkey tests commands
  3. Determine the Monkey test method
  4. Way to stop the monkey
  5. Monkey User Manual
  6. Monkey Crash Log analysis
  7. Monkey ANR Log analysis
  8. Shut down during Monkey tests
  9. Monkey operation mechanism

1. Complete the monkey test command

The system test ignores the monkey test interruption caused by crash timeout security-exceptions and saves the Log in the specified file.

adb shell monkey --ignore-crashes --ignore-timeouts --ignore-security-exceptions --throttle 100 -v 999999999 > monkey_log.txt

2. App Monkey test commands

App test is performed. If crash occurs, crash information will be printed to facilitate us to solve the crash. Adb shell monkey -p com.qiyi.video

Test methods such as Crash ANR and security exception were ignored.

Adb shell monkey -p com.qiyi.video (ignore-crashes --ignore-timeouts --ignore-security-exceptions --throttle 100 -v 999999999 > monkey_log.txt

3. Determine the Monkey test method

   /**
    * Returns true if Monkey is running.
    */
   public static boolean isMonkeyRunning() {
       return ActivityManager.isUserAMonkey();
   }
Copy the code

4. Ways to stop the monkey

  • A. Check the processkilloffmonkeyProcess View mobile phonemonkeyProcess commandadb shell ps |findstr monkey, through the wait processid(Adb shell kill -9 18333 (monkey process ID)), implement stopmonkeyThe test.
C:\Users\Administrator>adb shell ps |findstr monkey
shell     18333 273   1627720 34672 binder_thr 759b3b8884 S com.android.commands.monkey

C:\Users\Administrator>adb shell kill18333-9Copy the code

  • B. Restart the mobile phone

Such schemes are simple and violent.

5. Monkey Instruction manual

Adb shell monkey-help: adb shell monkey-help

  • -v registers Log information

  • — Throttle specifies milliseconds

  • -s sends random number seeds

  • -p indicates the name of the test Monkey APP package

6.Monkey Crash Log analysis

In the captured adb log, open it using a text editor (Notepad++ is recommended for case matching),

Search for the keyword CRASH:

Monkey ANR Log analysis

In the captured adb log, open it using a text editor (Notepad++ is recommended for case matching),

Search for the keyword ANR in or NOT RESPONDING

If ANR exists, pull out the trace file under data/ ANR to help analyze ANR causes.

Run the following command to export ANR files: adb pull data/ ANR.

8. Shutdown during Monkey test

To start shutting down your Monkey test, do the following. 1. Search battery_level to view the battery level. You can view the battery quantity, battery voltage, and battery temperature information in events_log.

9.Monkey operation mechanism

Jar is packaged into system/framework/, so the monkey command can be run directly on the phone.

The script for executing the monkey command is stored in the system/bin directory. You can use this script to test monkey commands.

At this point, this has ended, if there is wrong place, welcome your suggestion and correction. Meanwhile, I look forward to your attention. Thank you for reading. Thank you!