GlobalLogic provides experience design, digital product engineering services and Agile software development to global brands in all vertical industries.

Android Automation: Open Source Frameworks

December 24, 2017

Android app developers can significantly accelerate their time-to-market through testing frameworks that automate crucial but repetitive tasks. In this blog, we review several open source frameworks, including those for functional (acceptance) and regression testing:

Android frameworks

Android Instrumentation

Here are three frameworks that belong to the Android Instrumentation testing category, as specified in the family tree of test frameworks shown above.

Robotium

Robotium is an Android test framework that has full support for native, hybrid and mobile web applications. Native apps are those written using the Android SDKs. Mobile web apps are web apps accessed using a mobile browser. Hybrid apps have a wrapper around a “Webview” — a native control that enables interaction with web content.

Robotium is an instrumentation-specific open test framework maintained by the Google community. Robotium JAR will be integrated with the IDE. The test script will be created by using a programming language such as Java, and it will be integrated with Android Junit4. The test package will be created based on the written test script, and the test package directly interacts with the instrumentation runner available in the Android Dalvik Virtual Machine. The same request will trigger user action in the target package, which is nothing but the mobile application being tested.

Robotium is used to perform the instrumentation-specific testing in which, without getting the source code, the mobile application can be automated using the APK to cover the black-box testing.

Espresso

Espresso is an Android test automation framework used to test a native application. All the activity-specific action can be tested by using Espresso, which was released by Google. Espresso will concentrate only on the user interface testing in accordance with the unit testing point of view. The working mechanism behind Espresso is as follows:

  • ViewMatchers – allows to find view in the current view hierarchy
  • ViewActions – allows to perform actions on the views (Click, swipe, etc.)
  • ViewAssertions – allows to assert state of a view (True or False)

Calabash

Calabash, a behavior-driven development tool, is an open test framework used to automate testing for Android mobile applications based on native, hybrid and mobile web code. Its working mechanism is nothing but Cucumber Gherkin, which has been integrated with the Calabash gem to execute the test scripts written as a feature file.

It’s an open source framework available in GitHub with source information. You can run the test script on multiple emulators/real devices connected to a single machine. Test steps written in simple English language can trigger certain actions in the mobile application when executed.

UI Automator

The UI Automator testing framework provides a set of APIs to build UI tests that perform interactions on user apps and system apps. The UI Automator APIs allow you to perform operations such as opening the Settings menu or the app launcher in a test device.

The UI Automator testing framework is well-suited for writing black box automated tests, where the test code does not rely on internal implementation details of the target app. It will directly interact with the UI elements associated with the mobile application, which trigger all the user actions such as entering the text in the text box, click action, swipe, drag to, multi-touch, etc.

Appium

Appium is an open-source tool for automating native, mobile web, and hybrid applications on Android platforms.

Appium aims to automate any mobile app from any language and any test framework, with full access to back-end APIs and database from test code. Write tests with your favorite dev tools using all the above programming languages, and probably more (with the Selenium WebDriver API and language-specific client libraries).

Appium test scripts written in IDE will interact with the Appium Server, which is nothing but the node server with the specified IP address and port number. The node server then passes the request to mobile devices or emulators using the UI Automator in a JSON format. All the UI elements associated with the mobile application can be controlled by using the Appium client, which is derived from Selenium. The Appium work flow is summarized in the following diagram:

Appium flow

Comparison Matrix

Here is a useful matrix for comparing the features available with the frameworks discussed in this article.

Comparison matrix