Now, there are a number of Android Automation test architectures or tools available for us to use, including Activity instrumentation, Monkeyrunner, Robotium, and Robolectric. In addition, Lesspainful also provides services for automated testing on real-world devices.
Android itself provides basic support for instrumentation testing, One of these is the ActivityInstrumentationTestCase2 class in the Android.test package, which expands the JUnit TestCase class to provide functional testing of the Android activities. In the application test, each activity is first initialized by instrumentation and then loaded into the Dalvik virtual machine of the Android emulator or device.
The Android SDK comes with a test tool Monkeyrunner, which provides the API and execution environment to run test code written in the Python language. It provides APIs to connect devices, install/uninstall apps, run apps, take screenshots, and compare images to determine if a particular command's screen contains expected information and run tests on the app. Monkeyrunner using ActivityInstrumentationTestCase2, Providertestcase,servicetestcasek, Singlelaunchactivitytestcase and other classes to define test cases and use the Instrumentationtestrunner class to run tests.
Robotium is another architecture that accomplishes Android interactive testing through Instrumentationtestrunner, spanning multiple activities, supporting functional testing, system testing, and receiving testing. Robotium supports activities, Dialogs, Toasts, Menus, Context Menus, and even honeycomb, and it can integrate with Maven and ant to complete continuous integration testing. Robotium is called another selenium for Android apps.
Robolectric is not dependent on the testing capabilities provided by Android, it uses the shadow objects and runs the test on a normal workstation/server JVM, unlike a simulator or device that requires dexing (Android The Dex compiler compiles the class file into the format used by the Dalvik VM on the Android device, and the process of packaging, deploying, and running greatly reduces the time of the test execution. The pivotal lab claims that using Robolectric can run 1047 tests in 28 seconds.
Lesspainful The Android test a step further, it provides a multi-device platform for automated testing services. User Upload Application (*.apk) and test files written in cucumber (a business-related DSL), select the device configuration required for the test run, and the final test will automatically execute and generate the test report. The devices it supports include Garmin Asus, several Htc,lg,samsung galaxy,sony Xperia and Motorola Motodefy.
To learn more about the details of the service provided by Lesspainful, we interviewed Lesspainful CEO Jonas Maturana Larsen. Here is a brief visit:
InfoQ: What's the problem with running applications on different versions of Android? To ensure that the program runs properly, does the developer need to test his app on every version of Android?
JML: For example, before Android 2.2, SAXParser had a bug that existed in the callback to Contenthandler.startelement, which caused the application to produce the wrong behavior.
So far, we have found differences between different operating system versions in many ways. Some of these may cause crashes on 2.1-update1, but can run normally on 2.1-update3 and 2.2.
InfoQ: Is there a real difference between devices for Android? Can you give us an example of a Android2.2 app that can run on HTC but not run on Samsung? (or a combination of other Android versions and device manufacturers)
JML: on LG phones, Horizontalscrollviews sometimes causes the background picture on the child view to disappear. This problem exists in all of the LG phones we tested, no matter what the Android version is.
If you do not handle this type of problem yourself, it will cause your app to vary across devices. For example, Motorola will highlight an input field with a red border. In a project I used to participate in, we used the same red border to indicate that the input was wrong.
There are also issues that are more related to the hardware than the manufacturer: for example, some phones use smaller RAM and high-resolution cameras, which can cause crashes when you process images on your phone.
InfoQ: How are these tests performed?
JML: testing is like running a ActivityInstrumentationTestCase2, mainly using Robotium to run. The only change we make to the app is to remove the existing signature and regenerate our signature file for it.
After the test run is complete, the app will be uninstalled and the phone will be restored to its original settings.
InfoQ: What are the advantages of the services you offer compared to Monkeyrunner,robotium and robolectric?
JML: Lesspainful is a service, not just an architecture. We want to create a service that not only enables testing, but also saves us a lot of testing time and can help us find more bugs than any other architecture.
In addition, we believe that the use of cucumber can clearly define high-level test descriptions and be better shared by people outside the development team.
In Git, for example, we want to be like GitHub, not just the usual git libraries.
InfoQ: Do you have any plans to support more devices in the future?
JML: yes. We plan to continue to increase support for more devices. If there is such a request, we will try to finish it.
We are also working on support for iOS devices and hope that the beta version will be released this fall.
InfoQ: What is lesspainful Enterprise Edition?
JML: We will provide a toolset that is similar to a Mac Mini, but we will be very flexible to meet the needs of customers. Lesspainful Enterprise Edition is not yet officially launched, so please look forward to it.
English Original: Automated testing Solutions for Android