I made my test-runner inherit from InstrumentationTestRunner and took the extra data in onCreate():
public class DepponTestRunner 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 -e class test类全名\#方法名 -e foo june123456789asdfghjklqwertyuiopzxcvbnm -e bert june123 -w com.deppon.app.june.test/deppon.util.DepponTestRunner
public class DepponTestRunner 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 -e class test类全名\#方法名 -e foo june123456789asdfghjklqwertyuiopzxcvbnm -e bert june123 -w com.deppon.app.june.test/deppon.util.DepponTestRunner
本文介绍如何通过继承InstrumentationTestRunner创建自定义的测试运行器DepponTestRunner,并在onCreate()方法中处理额外的数据参数。此外,还展示了如何在Android.mk文件中添加依赖项,在AndroidManifest.xml中注册自定义测试运行器,以及使用命令行运行测试。
2468

被折叠的 条评论
为什么被折叠?



