Automated Testing of Application on Android using ROBOTIUM – Part 4

In continuation to my previous blog where we learned how to create and execute test scripts creating for Android applications using Robotium, in this blog we will discuss how to create configuration file and create data-driven test.

Maintaining Configuration Properties

To maintain configuration properties like Database Path, Data Tables details, initially I thought of using some external XML API. However, after going through the internal file structure of an Android project and how it is deployed on the device, I decided to store config properties in Android specific XML files. This does not require us to import external XML handlers and simplifies the process of reading config properties.

However we still need to figure out which Android config file to use to store user specific config properties. I stored the config properties in Strings.xml file as described below.

• Navigate to res folder of your project.

• Open res/values and open String.xml file

• Click Add and select String. Click OK

• Enter the config property name in “Name*” and the value in “Value*”

E.g.:

Name*: DB_Name

*Value*: SMS.sqlite

• Save Strings.xml file and close

Once the config properties have been created, we can use them in our script like:

mycontext= getInstrumentation().getContext();

String sDB_Name=mycontext.getResources().getString(R.string.DB_Name); //”sms.sqlite”;

String sDataTable=mycontext.getResources().getString(R.string.DataTable); //”SMS_Data”;

Data Driven Approach

Having identified the approach for config properties, then I thought of implementing Data driven approach. My initial idea was to use Apache POI excel handlers and I found some challenges in implementing external excel interface due to the factors mentioned below.

• We need to include external JAR file in the test project. Using external JAR, increases Android Build File (.apk) file size taking more memory on the device and increases in test framework deployment time.

• Creating an excel file and loading in the device is very complex. Also we need to write additional code to open the excel file, read from the file during execution further increases the memory footprint of the test framework.

I thought of implementing Data Driven Testing using the internal database of Android i.e. SQLite database which rules out the option of handling external data sources reducing the effort of reading, loading and using the data within the scripts to perform Data Driven Testing.

Using SQLite test data provides us with the following advantages.

1. Storing Test Data in Database makes execution very fast (data retrieving through queries) compared to approaches like using Apache POI to external excel files.

2. Since SQLite is a built-in database, no need to add any external resources like external jars and gives us following advantages:

a. Database can be integrated along with build.

b. Reduces size of APK File which leads to reduced application deployment time and memory footprint of the test framework.

androidddt.png

SQLite DB can be created using different tools. But using SQLite Manager FireFox addon is very flexible.

SQLite Manager FireFox addon can be downloaded from https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/

Reference to previous blogs: http://www.allianceglobalservices.com/blog/kkambham/

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>