我正在使用取决于如果我在开发模式或设备测试命令行或月食我的Android JUnit测试。
Java应用程序具有主(字符串[] args)方法,很容易将参数传递给它(具有在运行配置部Arguments标签蚀,或通过命令行)
对于一个Android JUnit测试它是不同的,不存在主要方法有无处我可以设置一些参数。
我看过这里有一个解决办法是使用属性文件。 这是唯一的办法? 如果你AVE一个快速和简单的例子,这将是非常赞赏。
谢谢
>>> Edit <<<
我使用Robotium,和JUnit延伸ActivityInstrumentationTestCase2请参见下面的非常基本的JUnit测试:
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");
}
}
和Android清单
<?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>