开发者

GUI testing with Instrumentation in Android

开发者 https://www.devze.com 2022-12-27 06:19 出处:网络
I want to test my Android applications UI, with keyevents and pressed buttons and so on. I\'ve read 开发者_Go百科som documentation that Instrumentation would be able to use for this purpose.

I want to test my Android applications UI, with keyevents and pressed buttons and so on. I've read 开发者_Go百科som documentation that Instrumentation would be able to use for this purpose.

Anyone with expericence with using Instrumentation for UI testing?


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.


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?


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.


There is some new UI Testing tool which launched with SDK tools revision 21:

UI Automator Test Framework
One common approach to UI testing is to run tests manually and verify that the app is behaving as expected. UI Automator is a new software testing framework available in Tools R21 that provides you with tools to easily automate UI testing tasks. It provides a GUI tool to scan and analyze the UI components of an Android application (uiautomatorviewer), a library containing APIs to create customized functional UI tests, and an execution engine to automate and run the tests against multiple physical devices. UI Automator runs on Android 4.1 (API level 16) or higher. To learn more head over to the UI Testing documentation.

Source: http://android-developers.blogspot.de/2012/11/android-sdk-tools-revision-21.html

0

精彩评论

暂无评论...
验证码 换一张
取 消