0

我尝试测试一个应用程序,该应用程序每次启动时都会启动一项特殊活动。让我们称之为 Activity AlreadyStartedActivity。测试用例如下所示:

public class AlreadyStartedActivityTest extends ActivityInstrumentationTestCase2<AlreadyStartedActivity> {

    public AlreadyStartedActivityTest() {
        super(AlreadyStartedActivity.class);
    }

    public void testStart() {
        Solo solo = new Solo(getInstrumentation(), getActivity());

        // use solo to click and test some features of the activity.
    }
}

问题是AlreadyStartedActivity配置AndroidManifest.xml如下:

<activity android:name=".activity.AlreadyStartedActivity"
        android:taskAffinity=""
        android:excludeFromRecents="true"
        android:launchMode="singleTop" />

singleTop避免调用,这将永远AlreadyStartedActivity#onCreate阻止该方法。getActivity

我能做些什么来避免这种情况吗?

问候

4

1 回答 1

0

It looks like you haven't properly setup test class. You need to add default constructor:

public class AlreadyStartedActivityTest extends
        ActivityInstrumentationTestCase2<AlreadyStartedActivity> {

    public AlreadyStartedActivityTest() {
        super(AlreadyStartedActivity.class);
    }

    public void testStart() {
        Solo solo = new Solo(getInstrumentation(), getActivity());

        // use solo to click and test some features of the activity.
    }
}

And probably it is better to move Solo to setUp() method.

于 2013-04-09T12:17:32.750 回答