如何制作可以启动我的Robotium测试的APK?

时间:2012-03-21 05:13:12

标签: android testing robotium

(A)要测试的应用程序(例如浏览器)

(B)测试应用程序。 (扩展ActivityInstrumentationTestCase2)(Robotium)

(C)启动器(如“devTools” - > Instrumentation)

如何创建可以启动测试应用(B)的APK(C)。

1 个答案:

答案 0 :(得分:2)

public class Main extends Activity {

protected List<InstrumentationInfo> mList;
protected ComponentName mBrowserTestComponent;
protected final static String TARGET_PACKAGE = "com.android.browser";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mList = this.getPackageManager().queryInstrumentation(TARGET_PACKAGE, 0);
    mBrowserTestComponent = instrumentationForPosition(0);
}

public void startTesting(View view) {
    this.startInstrumentation(mBrowserTestComponent, null, null);
}

public ComponentName instrumentationForPosition(int position)
{
    if (mList == null) {
        return null;
    }
    InstrumentationInfo ii = mList.get(position);
    return new ComponentName(ii.packageName, ii.name);
}
}