The easy way to test Android applications

Renas Reda

I’m going to guess that most of you know what instrumentation is. In the event that you don't, instrumentation is a feature in which specific monitoring of the interactions between an application and the system is made possible. Instrumentation also makes it possible to write test cases that interact with the application. The problem with instrumentation, however, is that it is incredibly hard to write solid test cases for applications bigger than the typical “Hello World!” application. A tremendous amount of technical details must be taken into account in order to write a good test case. Often, developers quickly realize that it will take almost as long to write a comprehensive test case as it took to write the whole application. I, myself, came to recognize the very same thing when I first started looking into how to use instrumentation tests with the android application project that I’m currently working on.

I soon came to understand that I would not be able to take advantage of all the wonderful possibilities that instrumentation offers. The reason for that is quite simple; the application that we are in the process of developing is not only extensive but also complicated with multiple activities, self-defined intents, and hundreds of views that also include scrollable lists. It would not make sense for me to spend a month writing one single test case that would only take 20 seconds to test manually. That is how Robotium-Solo was born. I needed a test framework that would help me write good and powerful test cases that emulated real users. The test case should be able to do what a real user does: click on anything that is clickable, look for irregularities, automatically move from activity to activity, etc. More importantly, I should not have to spend more than 10 minutes writing a test case that involves more then one activity.

With the help of Robotium-Solo a test case spanning over multiple activities could look like this:

public void testTextIsSaved() throws Exception {
   solo.clickOnText("Other");
   solo.clickOnButton("Edit");
   assertTrue(solo.searchText("Edit Window"));
   solo.enterText(0, "Some text for testing purposes")
   solo.clickOnButton("Save");
   assertTrue(solo.searchText("Changes have been made successfully"));
   solo.clickOnButton("Ok");
   assertTrue(solo.searchText("Some text for testing purposes"));
}

As you can see, I don’t have to specify any technical details or tell Robotium-Solo where to look for something, such as scrolling down a list when needed. It handles the above and more all on its own.

If you are interested in writing test cases of similar nature have a look at http://www.robotium.org. It makes writing powerful test cases a breeze.

Renas Reda
Consultant at Jayway

Tags: , , , ,

5 comments ↓

#1 ram on 02.19.10 at 10:28

please tell me the details about how to use Robotium-solo……………
i have download .jar file. what should i do with that??

#2 Renas Reda on 02.19.10 at 11:47

Hi,

Please go to our Getting Started page: http://code.google.com/p/robotium/wiki/Getting_Started

There you will find instructions as well as an example test project that you can use.

Sincerely,
Renas

#3 Prasanna on 06.24.10 at 22:16

Hi Renas,
I’m trying to test a date picker scenario on a form. I have the date picker which comes up when I click a text view which has a label on it along with a hint Enter Date.

The problem is that I’m trying to simulate this clicking of the text view and then selecting of the date from the date picker dialog. I cannot find an method call/option in Solo to get hold of the text view (ex:with id say x).
I’ve been trying to figure it out for the past three days.
Will you suggest me a way to go about it?.
Sorry to have posted this question in here.

Thanks
Regards

#4 Renas Reda on 07.05.10 at 18:38

Hi,

You can use clickOnView() if you want to click on a view with its ID. An example is:

solo.clickOnView(solo.getCurrentActivity().findViewById(com.example.android.notepad.R.id.note));

Sincerely,
Renas

#5 Sakib Choudhury on 08.09.10 at 0:25

hi Renas,

i really love your robotium, have been using it for testing purpose for the last 3 weeks. but here is a problem i am facing. is robotium able to test across various activitities? our application is quite complex and we have to test the whole application starting from one activity (as it is not possible to figure out the actions of the other activities as they depend on the first activity, which passes on bundles to them). i am testing my project where i click on a checkbox to enter data in the database and then go out of the activity, and when i go back after a particular time, the checkbox should become unchecked again. we have some information on the top of the activity which contains the checkbox, and these information are generated from the database. now whenever i try to enter the activity using robotium, the application is crashing. but if i do it manually, nothing happens. so i was wondering if robotium is capable of testing through various activities

Leave a Comment