Reputation: 2752
I can launch my Android applications Junit/Robotium tests from the command line like this:
adb shell am instrument -w com.myapp.client.test/android.test.InstrumentationTestRunner
However, I want to somehow include a custom parameter that allows me specify whether the test is to be run in "Portrait" mode or "landscape" mode.
How can I:
specify that custom parameter in the command-line command?
How can I access that custom parameter's value in the Java code?
Thanks
Upvotes: 2
Views: 2960
Reputation: 2752
I made a hack solution to this. It doesn't look like there is a clean solution here.
My hack is to utilize the "small", "medium", and "large" attributes that you can attach to tests.
@MediumTest
public void testPortraitTest1() throws Exception{
this.MetaDataTest(Solo.PORTRAIT);
}
@LargeTest
public void testLanscapeTest1() throws Exception{
this.MetaDataTest(Solo.LANDSCAPE);
}
then you can use your batch file to call the medium tests first and then the large tests, like this:
adb shell am instrument -w -e size medium com.me.client.test/android.test.InstrumentationTestRunner
adb shell am instrument -w -e size large com.me.client.test/android.test.InstrumentationTestRunner
shame on google for not making this easier.
Upvotes: 0
Reputation: 857
You can specify a custom parameter using
adb shell am insrument -e <NAME> <VALUE> <package/runner>
You can reach it's value using the bundle that is available if you override the onCreate
method of the InstrumentationTestRunner
.
E.g:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
value = (String) savedInstanceState.get("name");
}
Upvotes: 4
Reputation: 522
The way I did this is:
Before I run the test, I save a text file in the sdcard\
When the test starts, in the setUp, I parse each line of the text file and extract the key/value
arg1=valueX arg2=valueY
Upvotes: 0
Reputation: 43
You can extend Android Instrumentation runner and override oncreate() method to get custom parameter from command line. Use your customized instrumentation runner while executing test cases.
public class CustomInstrumentationRunner extends android.test.InstrumentationTestRunner{
@Override
public void onCreate(Bundle arguments) {
//process you parameters here.
super.onCreate(arguments);
}
@Override
public void onStart() {
try {
logger = CustomLogger.GetLogger();
} catch (Exception e) {
throw new RuntimeException(e);
}
super.onStart();
}
Upvotes: 3