在 Android 中使用 Instrumentation 进行 GUI 测试
我想测试我的 Android 应用程序 UI,包括按键事件和按下的按钮等。我已经阅读了一些仪器可以用于此目的的文档。
有人有使用 Instrumentation 进行 UI 测试的经验吗?
I want to test my Android applications UI, with keyevents and pressed buttons and so on. I've read som documentation that Instrumentation would be able to use for this purpose.
Anyone with expericence with using Instrumentation for UI testing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
官方推荐的在 Android 上执行 UI 测试的方法是插装,是的。查看 InstrumentationTestRunner。此类功能存在一些包装器,可以减轻使用时的痛苦,其中之一是 Robotium< /a>,另一个是Calculon。
然而,现在大多数人似乎都同意谷歌的测试框架是失败的。它非常不稳定、非常慢,而且 API 很糟糕,使得测试难以编写和理解。因此,我认识的大多数运行较大测试套件的人都会选择 Robolectric,这使得 UI 测试脱离了设备和 Dalvik 到普通的旧 JVM。它已经取得了长足的进步,并且现在实际上非常有用。一探究竟。当然,主要缺点是它不会实际在设备上检测应用程序,甚至不会渲染 UI。它在代码级别进行断言,因此它不是黑盒测试的正确选择。
另一种黑盒/端到端测试应用的方法是 Selenium + NativeDriver。 NativeDriver 是 WebDriver API 的实现,因此您可以针对 Android 设备运行 Selenium 风格的测试。
另外一个值得一提的工具是 Android 自己的 monkeyrunner (不是 Monkey UI 练习器) ,它只是将随机事件发送到设备,使其可用于压力测试,但不适用于功能测试)。 Monkeyrunner 是一个 Python 脚本设备桥,您可以通过它发送击键和点击来检测您的应用程序。再说一遍,我不建议使用它,因为它充满了错误并且功能非常有限。不过它还可以做其他事情,例如截取正在测试的应用程序的屏幕截图。
The officially recommended way to perform UI tests on Android is instrumentation, yes. Have a look at InstrumentationTestRunner. There exist wrappers for this sort of functionality which make it a little less painful to use, one of these is Robotium, another is Calculon.
However, most people seem to agree these days that Google's test framework is a fail. It's very flaky, very slow, and the APIs are terrible, making tests difficult to write and understand. Hence, most people I know that run larger test suites opt for Robolectric, which takes UI testing away from the device and Dalvik to a plain old JVM. It has come a long way, and is actually very usable these days. Check it out. The main drawback is of course that it won't actually instrument the app on a device or even render the UI. It makes assertions on code level, so it's not the right choice for black box tests.
Another way to black box / end-to-end test your app is Selenium + NativeDriver. NativeDriver is an implementation of the WebDriver APIs, so you can run Selenium style tests against your Android devices.
One more tool to mention is Android's own monkeyrunner (not the Monkey UI exerciser, which simply sends random events to a device, making it useful for stress testing, but not for functional testing). monkeyrunner is a Python scripted device bridge, against which you can send keystrokes and taps in order to instrument your app. Again, I wouldn't recommend using it though, since it's riddled with bugs and has very limited functionality. It can do other things though, such as taking screenshots of your app under test.
我对 Instrumentation 不熟悉,但是 Android 附带了一个名为 "Application 的工具锻炼猴”。它会生成一系列随机用户输入,以在压力下测试应用程序。它易于使用,而且当您的应用程序在点击量涌入的情况下变得疯狂时,看起来有点有趣。这就是您要找的吗?
I'm not familiar with Instrumentation, but Android comes with a tool called the "Application Exerciser Monkey". It generates a stream of random user inputs to test the app under stress. It's easy to use and a bit funny to watch as your app goes crazy under the influx of clicks. Is that what you're looking for?
您提出问题已经有一段时间了,但也许我的回答仍然有帮助:
看看 robotium ,支持Android应用程序的黑盒UI测试。它无需检测您的生产代码即可工作,因此我希望检测对您来说不是严格的要求。
It has been a while that you asked your question, but maybe my answer is still helpful:
Have a look at robotium, which supports blackbox UI testing of Android applications. It works without instrumenting your production code, so I hope instrumentation is not a strict requirement for you.
有一些新的 UI 测试工具随 SDK 工具修订版 21 一起推出:
来源:http://android-developers.blogspot .de/2012/11/android-sdk-tools-revision-21.html
There is some new UI Testing tool which launched with SDK tools revision 21:
Source: http://android-developers.blogspot.de/2012/11/android-sdk-tools-revision-21.html