我正在尝试在交互活动通信中推送我的测试,并检查例如在正确登录后,我产生了正确的活动(来自 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 是否正在努力对每个产卵过程进行沙箱处理。我真的很喜欢 robolectric 中的链式活动测试示例。谢谢。