How to pass an argument to an AndroidTestCase?
Found a solution.
I made my test-runner inherit from InstrumentationTestRunner and took the extra data in onCreate():
public class MyTestRunner extends InstrumentationTestRunner {
public static String BAR;
public void onCreate(Bundle arguments) {
if (null != arguments) {
BAR = (String) arguments.get("foo"));
}
super.onCreate(arguments);
}
}
I added to Android.mk:
LOCAL_JAVA_LIBRARIES := android.test.runner
And to AndroidManifest.xml:
<instrumentation
android:name="com.example.MyTestRunner"
android:targetPackage="com.example" />
Ran it using this command line:
adb shell am instrument -w -e foo the_value_of_bar com.example/com.example.MyTestRunner
I was able to get the 'foo' parameter from the command line and use BAR in my AndroidTestCase.
Run Junit test using android instrumentation on a package with classes in specific order
I finally got it to work using the following command :
adb shell am instrument -e class com.android.foo.LaunchTest -w com.android.foo/android.test.InstrumentationTestRunner
Start Android activity from command line with extra
The right command should be
adb shell am start -n com.example.mike.app/.SimpleActivity --es "Message" "hello!"
with -n
....
Related Topics
Change Device Language via Adb
How to Open Navigation Drawer with No Actionbar, Open with Just a Button
Android Button Background Color
Triggering Event When Button Is Pressed Down in Android
Convert Existing Project to Library Project in Android Studio
Switching Between Fragment View
Changing Locale: Force Activity to Reload Resources
Android, Landscape Only Orientation
How to Get Dependencies from Jcenter with a New Project
Copy Database File to Sdcard in Android
How to Add .So Files to an Android Library Project Using Gradle 0.7+
How to Get Information About Android Battery Usage by Application