How to make APK that can launch my Robotium test?

房东的猫 提交于 2020-01-05 09:04:34

问题


(A) App to test (eg. Browser)

(B) Test app. (extends ActivityInstrumentationTestCase2) (Robotium)

(C) Launcher (like "devTools" -> Instrumentation)

How can I create an APK(C) that can launch the Test app(B).


回答1:


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);
}
}


来源:https://stackoverflow.com/questions/9798952/how-to-make-apk-that-can-launch-my-robotium-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!