Using Robotium with a Play APK

This tutorial will look at how we can use Robotium to run tests on Android applications where we don’t have the source code, only the APK from Google Play. It’s not meant as an extensive review of what Robotium is or how is compares to other testing frameworks, just the basics that are required to get started in a slightly less verbose fashion than the informative ‘official’ documentation. Robotium can be downloaded here and if you want to head straight to the Robotium documentation for this task, it’s here.

Firstly we need to choose an application to test and then re-sign the target APK with the Android Debug key (manual | tool). For PATH issues, try this.

The re-signer application will provide you with the package and main activity (see below), but you can get more detail of the Activities used in the app by decompiling with apk-tool.

Screen Shot 2013-04-03 at 22.57.22

Now that you have the Play APK re-signed with the debug certificate and installed on your device or emulator, you can start to create some test cases with Robotium.

  • Create a new Android test project.
  • Select a test project target of “This project” when prompted.
  • Under the ‘src’ folder, create a new package with the package name of the Application Under Test (AUT) plus “.test”. For me, the AUT package name was, so I used
  • Create a new class within this new package. This is going to contain your tests.
  • Within your project, create a ‘libs’ folder and add the Robotium jar to it. Then configure your build path to add this jar and also select it in the “order and export” tab.
  • Back in your class add the following code, changing package name as appropriate to your project;
  • edit the AndroidManifest.xml so that the instrumentation target package matches that of the AUT. In this example my manifest looks like this;
  • Now you can add tests to your java file, a very basic example might be as follows
  • 	public void testBasic(){
    		String XECurrency = "XECurrency";
    		solo.assertCurrentActivity("All good", XECurrency);
  • Once you have written some tests, you can run your application (as an “Android JUnit Test”) and watch as your tests run and (hopefully) pass.

As of version 4, Robotium can interact with WebViews/Hybrid apps, which I’d hope to have a look at very soon.