我尝试测试一个应用程序,该应用程序每次启动时都会启动一项特殊活动。让我们称之为 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
我能做些什么来避免这种情况吗?
问候