Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Android/ Robotium Instrumentation test cases against a release version APK?

I have an Android project setup with its pure Java unit test project running on PC, and its functional/ integration test projects running on Emulator. Those two make use of InstrumentationTestCase2 test cases and also Robotium framework. I'm able to run those two from Eclipse, against the debug version of my app and collect results and so on.

I'm able to create a release APK both thru Eclipse export and Ant build. APK is signed, zipaligned and obfuscated.

I'd like to know how to run those functional/ integration test against the release version of my app, instead of the debug one. I know I might encur in some errors because app project contains some test-only classes that probably have been stripped out by Proguard, but I can handle that.

I searched on Google and here on SO, but with no luck. There's only a page here related to testing with Robotium when you only have app's APK, no source. I'm not sure this would really help me. How would I get the test project to run on the device against the release APK?

like image 815
superjos Avatar asked Dec 16 '11 17:12

superjos


2 Answers

  1. Sign both the release app under test and the test Robotium app with your release key
  2. Install both apps on your device
  3. Run tests using the following command:

adb shell am instrument -w com.your.package/android.test.InstrumentationTestRunner

Where com.your.package is your package name.

See the Robotium Q&A for more info: http://code.google.com/p/robotium/wiki/QuestionsAndAnswers

As you mentioned, you might also have some Proguard issues depending on how you've written your test cases.

like image 123
theelfismike Avatar answered Sep 28 '22 13:09

theelfismike


I'd like to know how to run those functional/ integration test against the release version of my app, instead of the debug one.

I came across this question while searching for a solution..

Since this is an old question with old answers, I shall give an updated answer for Gradle-based Android project.

What I did is:

  1. let test apk run against release build type by adding this:
android {
    testBuildType "release"
}
  1. add proguard rules for your test apk as well
buildTypes {
    release {
        minifyEnabled true
        proguardFiles 'proguard-rules.txt'
        testProguardFile('proguard-rules.txt')
    }
}

Now try to run test against a release build. you may still encounter error due to proguard. if you are using Robotium, like I do, you can add the following line in your proguard-rules.txt file:

##--------------- Begin: proguard configuration for Robotium  ----------
-keep class com.robotium.** { *;}
##--------------- End: proguard configuration for Robotium  ----------

Hope it helps.

like image 23
xialin Avatar answered Sep 28 '22 14:09

xialin