我使用命令行或eclipse运行我的android junit测试,具体取决于我是在开发模式还是在设备测试中.
java应用程序有一个Main(String [] args)方法,很容易将参数传递给它(在运行配置部分的Arguments选项卡中使用eclipse,或者通过命令行)
对于一个android junit测试它是不同的,没有Main方法,我无处可设置一些参数.
我已经在这里阅读了一个解决方案是使用属性文件.这是唯一的方法吗?如果你有一个快速简单的例子,我将非常感激.
谢谢
>>> Edit <<<
Run Code Online (Sandbox Code Playgroud)
我正在使用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 = …
Run Code Online (Sandbox Code Playgroud)