Running Robotium Tests against Your Signed Android apk

Assuming you have an Android project and an associated Robotium test project, it is a relatively simple matter to run the tests against your signed-and-to-be-uploaded-to-the-market app. There are just a few steps and things to keep in mind

First, make sure that the test project is signed with the same certificate that you used to sign the app.

Second, and this caught me off guard, chances are that you will need to tweak your proguard config so that certain method and class names do not get obfuscated or removed. This will be necessary if your tests access any of the public classes or methods of the app being tested.

Here's what to add to you proguard.cfg file to keep a class and one of its inner classes from getting removed:

-keep public class com.whatever.app.SomeClassName
-keep public class com.whatever.app.SomeClassName$SomeInnerClass

Here's how to prevent the obfuscation of any methods in the class whose name contains the string "mainWidget"

-keepclassmembers public class com.whatever.app.SomeClassName {
*** mainWidget*(...);
}

There are other examples on the proguard site, and you can be very surgical in what you prevent from being obfuscated, if you've got the patience to learn the syntax.

And finally, you can run the tests from the commandline with adb; here are a few examples (each one is a single command).

Run all the tests in the class "com.whatever.app.test.ReleaseTests"

adb shell am instrument -w -e class com.whatever.app.test.ReleaseTests com.whatever.app.test/android.test.InstrumentationTestRunner

Run just the test "testOneLittleThing" in the class com.whatever.app.test.ReleaseTests

adb shell am instrument -w -e class com.whatever.app.test.ReleaseTests#testOneLittleThing com.whatever.app.test/android.test.InstrumentationTestRunner

If the tests don't run, make sure and take a look at logcat while the adb command runs. You might have missed some methods/classes when you told proguard what to not obfuscate. Logcat will be pretty nice and tell you which methods/classes it can't find.

You can attempt to do a dry run of all of the tests that will let you find all such missing method/classes via this command:

adb shell am instrument -w -e log true com.whatever.app.test/android.test.InstrumentationTestRunner

Popular Posts