The easy way to test Android applications

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 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 a test case spanning over multiple activities could look like this:

As you can see, I don’t have to specify any technical details or tell Robotium 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.

26 Comments

  1. ram

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

  2. Prasanna

    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

    • 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

  3. Sakib Choudhury

    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

  4. Joe Qu

    Hi Renas,

    I’m a big fan of your robotium tool, which makes my job much easier than without it.

    Right now I’m developing test cases that require multiple devices interacting with each other in a single case. But it seems robotium cannot do this now.
    So when are we expecting to see multiple-device support come online?

    Best regards,
    Joe Qu

  5. Color Pencils

    Does Robotium have Record-Play, instead of writing up the test cases? If so, could you point to the link? I couldn’t find it anywhere.

    Thanks,

  6. Derek Lu

    Thanks for your sharing.
    Now, I am tring to test through more activities. After one activity is done, it will jump out the application, in fact, there is another activity running on the application.
    How to fix this kind of issue, we cannot see all activities continually.

  7. SK

    Hi Renas,

    I have seen your Robotium demo written for Astro app on Youtube. Same thing I tried but I failed to execute. Can you please send me the full code of that.

    Thanks

  8. SK

    Hi Renas,

    I have seen your Robotium demo written for Astro app on Youtube. Same thing I tried but I failed to execute. Can you please send me the full code of that.

    Thanks in advance

  9. Great work on Robotium!

  10. hi renas, how do i add the robotium jar to my android test project without using eclipse? i tried adding the following:

    put the robotium solo jar in the libs dir of my test project
    added
    to the application node of my AndroidManifest in the test project

    the project compiles successfully (ant debug)
    when i go to install the test apk to my emulator i receive [INSTALL_FAILED_MISSING_SHARED_LIBRARY]

    what am i missing here? thanks in advance!

  11. Nithya Balachander

    Hello Renas…
    I am trying to use Robotium to test an .apk file assuming I have no access to the source code…I have multiple activities in my .apk file..
    Is there a way to call multiple activities in the same Test package file ??
    If so, How can I implement it ??

  12. Nithya Balachander

    Hello Renas…
    I am trying to use Robotium to test an .apk file assuming I have no access to the source code…I have multiple activities in my .apk file..
    Is there a way to call multiple activities in the same Test project file ??
    If so, How can I implement it ??

  13. Hi Renas….

    I am trying to use Robotium to test .apk file. How i can click image button in my .APK file????

  14. vijay

    how to read user data stored on sd card? i have istall application PRN _status on sd card and i ahve to read which data its stored on sd card is there any password stored at sd card??

  15. vijay

    how to read user data stored on sd card? i have istall application PRN _status on sd card and i have to read user data

  16. vijay

    Hi Renas,

    I have instatlled Android 4.0
    Robotium Solo 2.5 jar.
    I have created one small application from the blogs & when i try to run the application, Android Emulator is opened but, It shows the error message like

    java.lang.RuntimeException:Unable to resolve activityfor :Iintent{ act= android:intent.action.MAIN flg=0×1000000 cmp=com.calculator/.test.MyFirsrApp }
    at android.app.Instrumentation.startActivitySync(Instrumentation.java:370)
    at android.test.InstrumentationTestCase.launchActivityWithIntent(Instrumentation TestCase.java:119)
    at android.test.InstrumentationTestCase.launchActivity(Instrumentation TestCase.java:97)
    at android.test.InstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:098)
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
    at android.test.AndroidTestRunner.runTest
    (AndroidTestRunner.java:154)
    at android.test.InstrumentationTestRunner.Onstart(InstrumentationTestRunner.java.537)
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.javav:1551)

    When we click in the error message ,it shows that,Class File Editor
    Source not found –> msg is displayed..

    This is my issue…
    Kindly sort it out … ASAP

    Regards,
    Vijay

  17. mohan kumar

    Hey, good stuff,
    I’m working on WIFI implementation in android.
    can u tell me how to use Robotium for WifiManager class.

  18. Jeff Byer

    What is the answer to running a robotium test case on multiple devices at the same time?

  19. Sukanta

    how to pass arguments to the robotium from the command line(ubuntu terminal) to test the project as much time i want to test..means 10 times or 200 times as much time i wish..!!
    please share your experiance as soon as possible.

  20. suki

    hi,

    I want to do cts test, but it’s looking very complex to me. Can any one help me out by describing the cts test from the beginning. Means after setting up android sdk and avd plugins then what we have to do for doing CTS test. Please reply soon.. :)

  21. Daniel

    Hi ,

    doas robotium support multiple activity classes ?
    within my project i have 2 classes : Run1 and Run2

    both have editText i need to test together and also separattly this 2 editText

    how do i configure the test case class

    Thanks
    Daniel

  22. Daniel

    Hi, first i want to congrats for a very good product.
    Now, I’m wondering if it supports running it independently directly from the phone when the phone is disconnected.
    I give it a try with emulator and it runs nicely, but I want to use few phones and not all of them can be connected to the pc.

  23. Dhiraj Kumar

    Hi Renas

    I want to accsess id in test project but i dont have a source code i have .apk file so how can i acesses id in test project.

  24. musica

    Hi,

    How to resolve below error :
    java.lang.NullPointerException
    at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:117)
    at android.test.InstrumentationTestCase.launchActivity(InstrumentationTestCase.java:97)
    at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:104)
    at com.a.b.test.TestApk.setUp(TestApk.java:47)
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
    at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)

Leave a Reply