1

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
    }
indi mars
  • 133
  • 3
  • 8
  • I think the problem is you are setting up activity before you updated your `ApplicationSettings`. So call `Robolectric.setupActivity()` only after `ApplicationSettings.setWizardState()`. And I see number of wrong things - assert in setup, static method, using application context instead of activity context – Eugen Martynov Aug 07 '15 at 06:14
  • Thanks Eugen for your interest. I have updated my question. I tried all possible cases, infact I printed the value of Wizard State and it shows 22. – indi mars Aug 07 '15 at 10:10
  • But you should use now shadow of `loadAppDataActivity` – Eugen Martynov Aug 07 '15 at 10:27
  • Ohh Sorry its a copy paste mistake. This is actual class, but I am explaining as per my case study. – indi mars Aug 07 '15 at 10:30
  • Eugen, can you please this linkhttp://stackoverflow.com/questions/31869269/roboelectric-3-0-testing-fragments I am not able to get import for support fragment – indi mars Aug 07 '15 at 10:45

0 Answers0