Android Roboelectric 3.0 testing next activity –choosing from multiple activities

╄→尐↘猪︶ㄣ 提交于 2019-12-24 15:00:47

问题


I have scenario like this:--

I have three activities ActivityA(launcher activity), ActivityB, ActivityC Now in Activity A I read the Application context to decide whether to start ActivityB or ActivityC.

But even after setting the context value manual, the ActivityA is not updated and second test case fails. Any helps?

    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
    }

来源:https://stackoverflow.com/questions/31867722/android-roboelectric-3-0-testing-next-activity-choosing-from-multiple-activitie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!