Java 机器人分子测试中的链接活动

Java 机器人分子测试中的链接活动,java,android,testing,robolectric,Java,Android,Testing,Robolectric,我尝试在活动间通信中推送我的测试,并检查是否在正确登录后生成了正确的活动(来自2个可能的活动) 我的代码是这样的: @RunWith(GuiceRobolectricJUnitRunner.class) public class LoginActivityTest { @Inject private LoginActivity activity; @Inject private ExplorerActivity startedActivity ; @Inject private Context

我尝试在活动间通信中推送我的测试,并检查是否在正确登录后生成了正确的活动(来自2个可能的活动)

我的代码是这样的:

@RunWith(GuiceRobolectricJUnitRunner.class)
public class LoginActivityTest {
@Inject
private LoginActivity activity;
@Inject
private ExplorerActivity startedActivity ;
@Inject
private Context context;

private Button loginButton;
private EditText login;
private EditText password;

@Before
public void setUp() throws Exception {
    activity.onCreate(null);
    loginButton = (Button) activity.findViewById(R.id.identification_login_button);
    login = (EditText) activity.findViewById(R.id.txtLogin);
    password = (EditText) activity.findViewById(R.id.txtPassword);

}

@Online
@Test
public void shouldExploreWhenLoginIsCorrect() throws Exception {
    assertNotNull(activity);
    login.setText("test@test.com");
    password.setText("test");
    activity.setIntent(new Intent());
    loginButton.performClick();
    ShadowActivity shadowActivity = Robolectric.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = Robolectric.shadowOf(startedIntent);
    assertEquals(shadowIntent.getIntentClass(), ExplorerActivity.class);
//      startedActivity.setIntent(startedIntent);
//      startedActivity.onCreate(null);


    }
}

我的问题是无法从shadowintent中检索已启动的活动。我有没有办法做到这一点?此外,我没有看到我的探险家活动的任何痕迹,我想知道Robolectric是否在对每个产卵过程进行沙箱处理。我真的很喜欢机器人分子中链式活动测试的例子。谢谢。

因为已经三个月了,您可能已经找到了答案,如果没有,您可以在已有的基础上使用
newInstance()
,然后按照正常方式继续

ExplorerActivity explorerActivity = (ExplorerActivity) shadowIntent.getIntentClass().newInstance();
explorerActivity.setIntent(startedIntent);
explorerActivity.onCreate(null);

由于是3个月前,您可能已经找到了答案,如果没有,您可以在已有的基础上使用
newInstance()
,然后按照正常方式继续

ExplorerActivity explorerActivity = (ExplorerActivity) shadowIntent.getIntentClass().newInstance();
explorerActivity.setIntent(startedIntent);
explorerActivity.onCreate(null);