如何使APK,可以启动我Robotium测试? [英] How to make APK that can launch my Robotium test?

查看:99
本文介绍了如何使APK,可以启动我Robotium测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(一)应用测试(如浏览器)

(B)试验应用。 (延伸ActivityInstrumentationTestCase2)(Robotium)

(C)启动(如注明DevTools - >仪表)

我怎样才能创建一个APK(C),可以启动测试程序(B)。


解决方案

 公共类主要活动扩展{保护列表与LT; InstrumentationInfo> mList;
保护组件名mBrowserTestComponent;
保护最终静态字符串TARGET_PACKAGE =com.android.browser;@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);
    mList = this.getPackageManager()queryInstrumentation(TARGET_PACKAGE,0)。
    mBrowserTestComponent = instrumentationForPosition(0);
}公共无效startTesting(查看视图){
    this.startInstrumentation(mBrowserTestComponent,NULL,NULL);
}公共组件名instrumentationForPosition(INT位置)
{
    如果(mList == NULL){
        返回null;
    }
    InstrumentationInfo II = mList.get(位置);
    返回新组件名(ii.packageName,ii.name);
}
}

(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).

解决方案

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

这篇关于如何使APK,可以启动我Robotium测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆