This post is on the topic ‘Robotium – Testing Framework for Android’. I had worked on Robotium framework sometime back so just wanted to share the information related to the same with you all.

What is Robotium?

Robotium is a test framework created to make it easy to write powerful and robust black-box test cases for Android applications.

 

  • With the support of Robotium, test case developers can write function, system and acceptance test scenarios, spanning multiple Android activities
  • Robotium has full support for Activities, Dialogs, Toasts, Menus and Context Menus
  • Robotium is a Free tool, can be used by individuals and Enterprises
  • Robotium is a “Black Box” testing tool that is able to simulate and automate user interaction such as touching, clicking, text entry and any other gesture that is possible on a touch supported device
  • The tests could either be executed on the Android simulator (AVD – Android Virtual Device) or on a real device
  • Robotium is built on the Java programming language and the JUnit 3 test framework
  • Robotium can be used both for testing applications where the source code is available and applications where only the apk is available

 

Since the Robotium test tool is open source, no cost is associated with this.

Benefits of Using Robotium:

 

  • Easy to write, shorter code. Minimal time needed to write solid test cases
  • You can develop powerful test cases, with minimal knowledge of the application under test
  • The framework handles multiple Android activities automatically. Readability of test cases is greatly improved, compared to standard instrumentation tests
  • Automatic timing and delays
  • Automatically follows current Activity
  • Automatically finds Views
  • Automatically makes own decisions (ex: When to scroll etc.)
  • No modification to Android platform
  • Test execution is fast
  • Test cases are more robust due to the run-time binding to GUI components
  • Integrates smoothly with Maven or Ant
  • With the newly released Robotium 4.0, it has full support for hybrid applications. Hybrid applications are applications that use WebViews to present the HTML and JavaScript files in full-screen, using the native browser rendering engine

 

Robotium Features:

 

  • Screenshots can be captured inside Robotium
  • Robotium can be run without source code
  • It’s possible to generate code coverage reports for your Robotium tests
  • Robotium is able to detect the contents of a Toast on the screen
  • Localised strings can be used (Needs source code)
  • Robotium test can be run from the command line
  • Robotium offers many methods that react to different graphical elements within an Android app, such as

 

clickOnText(“Secure Login”);

 

clickOnButton(“Save”);

 

searchText(“Logout”);

 

goBack();

 

getButton();

 

isRadioButtonChecked();

 

  • With these simple methods, robust automated tests can be implemented really quickly. By combining them with JUnit, you then have additional ways of checking values or user interactions on the device for the correct response, which in turn makes these tests even more powerful

 

Limitations:

 

  • Cross Activities testing, Robotium is able to work only with same certificate app, otherwise you will get inject events exception (e.g. you are not able to do clicks on screen keyboard)
  • Robotium has no mechanism to handle expected/unexpected alerts/popus/dialogues. For example, iOS Javascript tests has very simple boolean flag and callback for handling alerts
  • Robotium has big problem with auto scrolling methods. For example, if you are looking for the text, which is not shown, Robotium will stack in the end of the scroll view and make assertTrue(false) to stop scrolling
  • Robotium has assertTrue(false) logic for reporting problems/unexpected situations instead of returning some Enum value or boolean (success/fail) so for a good stress tests which are run 24/7, you need to add your own methods which will not stop test, just handle ‘method fail to click x y’ result value
  • The scope of test cases in Robotium is limited to a single application and does not support for more than one application. Test project is always locked with a target package, which need to be tested and going outside of the package is not allowed
  • Android native API’s (Contacts, Widgets etc.) used in the Android application cannot be tested using Robotium. While executing test, if focus is switched to Native application, it will not come back to the Test application and Test will fail
  • Robotium is not able to handle the flash or web components. It only works with android components. You could send in clicks by using clickOnScreen() or assert that a certain Activity is shown but that is all. You will not be able to write tests where you verify or work with the web or flash components
  • Test Execution is very slow
  • Test cases are complex to implement
  • Not able to handle multiple activities
  • Robotium does not support flash and web based applications.
  • Robotium does not work on Canvas.

 

Future Enhancements:

 

  • Robotium Remote Control similar to Selenium RC
  • Integration with BDD tools such as cucumber
  • Automatic measurement of user interface test coverage
  • Generate screenshots on failure
  • Multiple device support

 

To get started with implementation, you can refer this link.

Talking off the topic, It’s great to be back on the blog after a long long time. I will make sure you get the latest updates on time 🙂

@MsWizKid signing off!

Enjoy 🙂

Android Development and Configuration in Eclipse

Hey Guys,

Hope you are doing good! 🙂

In this Article I will be explaining about the Android Development and how to setup android application development on Eclipse IDE . 🙂

Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language. Android offers a custom plugin for the Eclipse IDE, called Android Development Tools (ADT), that is designed to give you a powerful, integrated environment to build Android applications. [ The hyperlinks are displayed to give you more details about the specified keywords mentioned in the paragraph ).


Android 2.2 on Emulator

To start with the Development Part, you have to install Java platform (JDK)  first on your system and then  install the Eclipse IDE ,  Android SDK and the  Android Development Tool (ADT) plugin for Eclipse.

Download and Install JDK

Download and install the latest JDK (JDK 6 Update 24) from JDK download page .

Download and Install Eclipse IDE

Download and install Eclipse Classic 3.6.2 from Eclipse download page.

Download and Install Android SDK Starter Package

The Android SDK starter package includes only a single component i.e the latest version of the SDK Tools. Android SDK and AVD Manager is included in the same component which is used to download other components from the SDK repository site.

  • Download the latest Android SDK  starter package  from the SDK download page.
  • Unpack the archive to a suitable location on your system. By default, the SDK files are unpacked into a directory named  android-sdk-windows, if you are using the Windows as a Platform. 🙂

Add Android Platforms to Your SDK

To add more than one Android platforms (for example, Android 2.1 or Android 2.2) to your SDK, use the Android SDK and AVD Manager, included in the SDK starter package. It is recommended  to download multiple platforms, so that you can build your application on the lowest version you want to support. 🙂

  • Launch the Android SDK and AVD Manager on Windows by executing SDK Setup.exe at the root of the SDK directory.
  • On Available Packages menu, select the platforms to download.
  • Click on the Accept and Select all button and Install all the packages required.

Download and Install ADT Plugin

To install  the ADT ( Android Development Tool ) Plugin, you can take advantage of the Eclipse Software Updates Feature. By setting up a remote update site, you can easily download, install, and check for ADT updates.

  • Firstly, Launch Eclipse, then Select Help –>Software Updates.
  • In Available Software tab, click Add.
  • Enter a name for the site in the Name field and in the Locationfield, Enter the Following URL:
    https://dl-ssl.google.com/android/eclipse/ and then click OK. In the following snapshot I have already added the site so, I have selected the site from the list of available softwares. 🙂
  • Then Restart Eclipse.
  • To check whether the ADT has been installed correctly, Try to create a new project by selectFile > New > Project., you should find Android Project listed on project wizard.
  • Click on the Next and Create a new Project.
  • When you create the New Project in the Eclipse IDE, You can see the different types of files for the application development purpose having different meanings. They include:
  • AndroidManifest.xml snippet — This file is the application deployment descriptor for Android applications.
  • IntentReceiver – This demonstrates the implementation of an IntentReceiver, which is the class that processes intents as advertised by the IntentFilter tag in the AndroidManifest.xml file.  These Intents are basically used for the creation of the activity purpose. Activity Creation is basically a event generation to transfer the control of the program from one file to the another file with the useful parameters. 🙂
  • Sample.java — This implements an Android activity, the primary entry point to the sample application of this tutorial.
  • Main.xml — This contains the visual elements, or resources, for use by Android activities. This is the file where the GUI of the Android application get developed.
  • R.java — This file is automatically generated by Android Developer Tools and “connects” the visual resources to the Java source code.

Enjoy 🙂