我有这样的场景: -
我有三个活动ActivityA(启动器活动),ActivityB,ActivityC 现在,在Activity A中,我阅读了Application上下文,以决定是否启动ActivityB或ActivityC。
但即使在设置了上下文值手册之后,ActivityA也不会更新,第二个测试用例也会失败。有帮助吗?
private ActivityA activityA;
private ShadowActivity shadowActivity;
@Before
public void setUp() {
activityA = Robolectric.setupActivity(ActivityA.class);
assertNotNull("ActivityA not intsantiated", activityA);
shadowActivity = Shadows.shadowOf(activityA);
}
@Test
public void shouldStartActivityB() throws Exception
{
Intent intent = shadowActivity.peekNextStartedActivity();;
assertEquals(ActivityB.class.getCanonicalName(), intent.getComponent().getClassName());
}
@Test
public void shouldStartMainActivity() throws Exception
{
ApplicationSettings.setWizardState(RuntimeEnvironment.application, 22);
ShadowLog.d("Wizard state value", "" +ApplicationSettings.getWizardState(RuntimeEnvironment.application));// it prints 22
activityA= Robolectric.setupActivity(ActivityA.class);
shadowActivity = Shadows.shadowOf(activityA);
Intent intent = shadowActivity.peekNextStartedActivity();
ShadowLog.d("target activity is", intent.getComponent().getClassName());// This prints ActivityB instead of ActivityC
assertEquals(ActivityC.class.getCanonicalName(), intent.getComponent().getClassName()); // this test case fails
}