Robotium – basic setup and sample


  • Java
  • Eclipse
  • Android SDK with updated path variable
  • ADT plugin in eclipse

Steps for setting up proper environment for automation

  1. Install java
  2. Install eclipse
  3. Install android sdk
    with proper installation typing “adb” in command prompt from any path should give you something like this …                          
  4. Install adt plugin in eclipse.                                                                                    Above points can referred here and here
  5. Set android SDK location in eclipse.                                                                            In eclipse go to Window -> Preferences -> Android. With proper ADT plugin installation it should appear something like this ….                                                      Provide exact installation location of the android SDK here. If successful set you will see this                                              
  6. Create AVD.  In Eclipse go to Window -> Android sdk and avd manager. This will open up the “Android SDK and AVD manager” (you can also open it from windows programs and android SDK). Click on new and provide name, target(android version), sd card size, resolution(built in). After filling in all the required fields hit “Create AVD”                                                                                             Select the AVD created just now and hit “start” and then “launch”. This should launch the emulator with the above selected configuration.

Now everything is setup for running Robotium tests.

Running the sample test

  1. Download the sample code from here. Unzip the file to some location.
  2. Import the code into eclipse. In eclipse go to File -> Import -> Existing Projects into Workspace.                                                                                                        On successful import of the projects you should see all the project files and folders visible in the package explorer of eclipse.
  3. Install the app in the emulator. Download the FileManager app from here. (this app is signed with the debug key, details about signing apps with your own keys can be found here). From the saved path open a command prompt and type – adb install <app-name>.apk                                 
  4. Open the app “OI File Manager”(the application we installed) and click on “Accept” and “Continue” (I havent handeled this in the tests). Now we are all set to run the test.
  5. Select the test and run as “Android Junit tests”.
  6. In few secs you could see running tests. First time it fails(its intentional) and creates a screenshot, which is a very useful information for debugging. You can check out the code for how the screenshot is captured, its not a robotium feature, its achieved using native android apis. Open the app in the emulator you could see the screenshot named as ‘testname…..’ . After viewing get back to the view below in the app, you can hit back in the emulator.
  7. Run the tests again, it should pass.

You can enhance the tests further and use it for automating your own/other apps.



Sign apps with your key

When testing apps with Robotium it is required that the signature of the app and that of the test match. For apps created by us(or rather same IDE) it shouldn’t be a problem but for external(downloaded apps or apps not created by you) they don’t.

Every developer signs his apps with a key so that he is identified individually from everyone else. The apps built using eclipse by default is been signed by ‘debug’ key. The Robotium tests when run, using eclipse in our case installs itself as an app in the device/emulator. So essentially even our test gets signed using the debug key.

Now both these signatures should match. We cant sign our test using the app’s key because its obviously not at our disposal. What we can do is sign the app using our debug key. Now lets change the signature of FileManager app.

  1. Download the app from the above link.
  2. Download the re-signer jar from here. This jar is a drag and drop tool which rips off the signature from the app and leaves it off without any signature.
  3. Open the jar and drag and drop the app in the window.
  4. Provide file name of app and save. Now it will show the package and the main activity name. Save it some where, it is required when testing the app.
  5. Now that it doesn’t have any signature, lets sign it using debug key. Eclipse stores the debug key in a file debug.keystore in the location C:\Users\<username>\.android. Copy it to the java bin folder C:\Program Files\Java\jdk1.x.x\bin.
  6. Java comes with a tool called jarsigner which can sign files using the provided key. In the java bin folder open a command prompt in admin mode(it wont work without admin mode) and type this command.                                                                            jarsigner -verbose -keystore debug.keystore <filename>.apk androiddebugkey      The last part ‘androiddebugkey’ is the alias name of the keystore. After entering the command, when asked provide the password : android.
  7. You are done. You have the app now signed with the debug key.

Few hints/pointers

  • Always run in admin mode.
  • It might happen that the debug key has expired in which case, go to the debug.keystore location(provided above) and delete the file. Now come to eclipse select a android app/test and then hit Project -> Clean. A new debug.keystore file would have been created for you.