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?
Note: Instrumented test, also known as instrumentation tests, are initialized in a special environment that gives them access to an instance of Instrumentation. This class provides access to the application context and APIs to manipulate the app under test and gives instrumented tests their name.
Instrumentation tests. Instrumentation tests are tests that run on a device or an emulator and have access to instrumentation APIs. This means they have access to all the backend data and the structure of the app, but also know exactly what is displayed on the screen.
The Espresso Test Recorder tool lets you create UI tests for your app without writing any test code. By recording a test scenario, you can record your interactions with a device and add assertions to verify UI elements in particular snapshots of your app.
In summary, an instrumentation test provides a special test execution environment as launched via the am instrument command, where the targeted application process is restarted and initialized with basic application context, and an instrumentation thread is started inside the application process VM.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With