Automation Testing in Android Applications

DZone 's Guide to

Automation Testing in Android Applications

· Java Zone ·
Free Resource

In the recent years, with the advent of mobile devices, large numbers of people have shifted to mobile devices due to portability and ease of use.  Android has emerged as the leading platform for mobile devices in the recent years. Being a google product, it enjoys large marketing and subsequently fetches more customers.  Another major reason behind its immense popularity is that it is open source and has huge developer community developing thousands of application each day. Android is a java based application platform with linux kernel. It has designed its own compiler named Delvik which converts the android application code into machine code.

With the increasing popularity of android devices, the need for robust and reliable android applications has also increased. Testing has always played a very vital role in developing any application and its need is further highlighted in case of android application. The problem with android application testing is that it is not easy to test such mobile applications owing to novelty of platform and graphical user interface oriented application development of these applications.

Several automation tools are available in market which can be efficiently used to test traditional desktop based or web applications however in case of android it is not easy to automate testing owing to different constraints of mobile devices such as low power consumption CPUs, limited memory and small display. Furthermore, android development is at its infantry stages and due to lack of experience of android developers, android development is prone to several kinds of complex bugs which cannot be tested automatically.

Novelty  and Peculiarity of Android Applications

Android applications are not like traditional application in several aspects. Typical components of android applications are activities, broadcast receivers, content providers and services etc. These components are absent in traditional client server applications and event driven desktop applications. The tendency of bugs in android application is higher due to these factors and needs to be tested efficiently, hence automation testing, owing to its efficiency and reliability can be very handy to test these types of applications.

GUI based mobile applications are non-deterministic and user can click anywhere on the screen. Luckily, in mobile platforms like android, we can have separate development and deployment. We can simulate the behavior of android device on our PC. This opens door numerous number of test cases which can be easily tested on these simulators which otherwise would have required dedicated devices. These large numbers of test cases have made it really difficult to test all these applications. Automated GUI based testing can be very helpful to test applications in this context. Incorporating GUI Based automation testing in android application will improve application robustness in general and will help in regression testing in particular.

The strategy behind GUI based automation testing of android applications is that the tester writes test scripts which simulate the actual interaction of the user with graphical user interface of the device. The correctness of automated test cases depends upon these simulated interactions.  The flow control and state of application’s GUI can also be verified with this technique.

Android Application Testing Frameworks

Like other several capabilities, android comes with integrated testing strategies for automating the testing process. Two of the most famous android automated testing strategies are android instrumentation framework which comes with SDK and the other one is the positron framework model for automated testing.  

First we discuss the basis of instrumentation framework. Instrumentation of android applications refers to writing trace codes, event logging, debugging and using performance counters to monitor the flow control of an application. A number of supporting classes are present in android instrumentation framework which can be employed to start, stop, run and terminate any android application in the test environment.

In context of GUI testing, android consists of several screens called activities. An android application can be considered as a set of activities stacked on each other. Each individual activity further consists of a number of GUI based elements. Hence in order to test the GUI of an android application when has to go as deep as the individual components level of each activity and automated test case has to be written for each individual component. Android instrumentation framework provides ActivityInstrumentationTestCase2 for this level of GUI testing.

Positron Framework

In order to handle the activity resources, another client server based framework has been built on top of the instrumentation framework, called the positron framework for testing android applications. This framework utilizes high level approach in order to write and run automated test cases. Each state of the application is considered client. The client individually connects to the component of application on server which is running the activity. Connection between clients and server is established through Android Debug Bridge. Individual activity instances are created by the client to connect with. Thread safety is at the core of positron framework because in order to test GUI applications, GUI components usually run in a separate thread and corresponding events run in a separate thread to maintain the responsiveness of the application. Positron framework deals with each component on activity as arranged in hierarchical way.

Basic difference between the instrumentation and positron framework is that instrumentation framework performs automated testing at low level while simulating the interactions with the GUI. On the other hand positron frameworks perform testing at a higher level of automation and simulate GUI test cases in an abstract way.

It can be concluded from the above mentioned facts that owing to increasing popularity of android applications and the novelty of platform coupled with inexperience of android developer’s community, the proper testing of these applications is the need of the hour. Testing an android application is different from testing a simple desktop or a web application owing to its totally new architecture. Several tools are available to perform automated testing for android applications. These tools can also perform instrumentation and positron testing as aforementioned. 

One such tool available in market is “RoutineBot”. The tools contain all the features of any modern testing tool and can perform automated GUI testing efficiently. Details of this tool can be found at http://www.routinebot.com/. Happy coding!


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}