I am running my android junit tests using command line or eclipse depending if I am in dev mode or in device testing.
A java application has a Main (String[] args) method and it is easy to pass an argument to it (either with eclipse in the Arguments tab in the run configuration section, or by command line)
for an android junit test it is different, there is no Main method and there is nowhere I can set some arguments.
I have read here and there a solution would be to use a properties file. Is that the only way?
If you ave a quick and easy example, it would be very appreciated.
Thanks
>>> Edit <<<
I am using Robotium, and the junit extends ActivityInstrumentationTestCase2
See below the very basic junit test:
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import com.jayway.android.robotium.solo.Solo;
public class Test_arg extends ActivityInstrumentationTestCase2 {
private static final String TARGET_PACKAGE_ID = "com.myapp.test";
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.myapp";
private static Class launcherActivityClass;
private Solo solo;
static {
try {
launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public Test_arg() throws ClassNotFoundException {
super(TARGET_PACKAGE_ID, launcherActivityClass);
}
@Override
protected void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
@Override
public void tearDown() throws Exception {
try {
solo.finishOpenedActivities();
solo.finalize();
} catch (Throwable e) {
e.printStackTrace();
}
super.tearDown();
}
public void test_01() throws InterruptedException {
Log.i("TEST", "test");
}
}
and the android manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="5" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.slacker.radio" android:functionalTest="true"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner" />
</application>
</manifest>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…