How to use monkey and monkeyrunner tools for android testing?

后端 未结 4 1653
有刺的猬
有刺的猬 2020-12-16 16:08

How do you use monkey and monkeyrunner tools for android testing?

What are the basic commands needed?

相关标签:
4条回答
  • 2020-12-16 16:17

    These three steps should help you set it up:

    1 ) Get inside this directory - ~/Android/Sdk/platform-tools

    2) Start server - ./adb start-server

    3) Command to test 5000 random keystrokes in your app - ./adb shell monkey -p your.package.name -v 500

    For more information check this out. https://developer.android.com/studio/test/monkey.html

    0 讨论(0)
  • 2020-12-16 16:34

    Here are some useful tips when using monkey test.

    Specify one activity

    Add category in manifest:

    <activity android:name="MonkeyActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.MONKEY" />
        </intent-filter>
    </activity>
    

    and use command like this:

    adb shell monkey -p my.package -c android.intent.category.MONKEY -v 500
    

    Prevent notification disturb

    In Android 5.0+ you can use the feature Screen Pinning.

    • open this feature in "settings" > "security" > "screen pinning"
    • click recent/multitasking button beside home button
    • click the green pin icon to pin the Application you want to test

    then run your monkey test.

    stop monkeyTest

    Use the following command to stop monkey test:

    adb shell ps | awk '/com\.android\.commands\.monkey/ { system("adb shell kill " $2) }'
    

    reference

    • Android monkey test choose a specific activity
    • How do I stop the monkey madness?
    0 讨论(0)
  • 2020-12-16 16:40
    adb shell monkey -p com.bla.yourpackage -v 1000
    

    First is your package that you want monkey to run in and be restricted to. Second is i verbose mode, third is number of events to run.

    You can find out more by doing adb shell monkey -help

    0 讨论(0)
  • 2020-12-16 16:41

    monkey and monkeyrunner are different tools.

    Monkey

    You can run monkey from adb shell, then it will generate pseudo-random streams of user events. You can specify some conditions and constraints for the execution of these events (see documentation)

    The basic syntax is:

    $ adb shell monkey [options] <event-count>

    Monkeyrunner

    monkeyrunner is an API to control an Android device or emulator from outside of Android code, as the documentation defines. You can basically write Python scripts that describes some actions to be executed on target device.

    Sample Program

    Quoting Android Developers documentation:

    The monkeyrunner tool is not related to the UI/Application Exerciser Monkey, also known as the monkey tool. The monkey tool runs in an adb shell directly on the device or emulator and generates pseudo-random streams of user and system events. In comparison, the monkeyrunner tool controls devices and emulators from a workstation by sending specific commands and events from an API.

    0 讨论(0)
提交回复
热议问题