如何使用monkey和monkeyrunner工具进行android测试?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12294780/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use monkey and monkeyrunner tools for android testing?
提问by Terminator
How do you use monkey
and monkeyrunner
tools for android testing?
您如何使用monkey
和monkeyrunner
工具进行android测试?
What are the basic commands needed?
需要哪些基本命令?
回答by serenskye
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
您可以通过以下方式了解更多信息 adb shell monkey -help
回答by einverne
Here are some useful tips when using monkey test.
以下是使用猴子测试时的一些有用提示。
Specify one activity
指定一项活动
Add category
in manifest:
category
在清单中添加:
<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.
在 Android 5.0+ 中,您可以使用屏幕固定功能。
- 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 " ) }'
reference
参考
回答by emartinelli
monkey
and monkeyrunner
are different tools.
monkey
并且monkeyrunner
是不同的工具。
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)
您可以monkey
从运行adb shell
,然后它将生成用户事件的伪随机流。您可以为这些事件的执行指定一些条件和约束(请参阅文档)
The basic syntax is:
$ adb shell monkey [options] <event-count>
基本语法是:
$ 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.
monkeyrunner
是一个 API,用于从 Android 代码外部控制 Android 设备或模拟器,如文档所定义。您基本上可以编写 Python 脚本来描述要在目标设备上执行的一些操作。
Quoting Android Developers documentation:
引用 Android 开发者文档:
The monkeyrunner tool is not related to the UI/Application Exerciser Monkey, also known as the
monkey
tool. Themonkey
tool runs in anadb
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.
Monkeyrunner 工具与 UI/Application Exerciser Monkey 无关,也称为
monkey
工具。该monkey
工具adb
直接在设备或模拟器上的 shell 中运行,并生成用户和系统事件的伪随机流。相比之下,monkeyrunner 工具通过从 API 发送特定命令和事件来从工作站控制设备和模拟器。
回答by Febin K R
These three steps should help you set it up:
这三个步骤应该可以帮助您进行设置:
1 ) Get inside this directory - ~/Android/Sdk/platform-tools
1)进入这个目录 - ~/Android/Sdk/platform-tools
2) Start server - ./adb start-server
2)启动服务器 - ./adb start-server
3) Command to test 5000 random keystrokes in your app - ./adb shell monkey -p your.package.name -v 500
3) 在您的应用中测试 5000 次随机击键的命令 - ./adb shell monkey -p your.package.name -v 500
For more information check this out. https://developer.android.com/studio/test/monkey.html
有关更多信息,请查看此内容。 https://developer.android.com/studio/test/monkey.html