Shadow fragments in Robolectric?

I am currently trying to test android code with Robolectric. I need to check that the package I am sending with the intent to create a new activity contains what I expect.

Looking around the internet I found a mention of ShadowFragment in Robolectric 2.0-alpha 1 documents that has getArguments (), it looks like it will do what I need, but it doesn't seem to be mentioned at all in the 2.4 docs and I can't get the org.robolectric.shadows.ShadowFragment for a solution.

Has it moved, is there a workaround, or is there some other direction I need to test the action pack in Robolectric?

Any help would be greatly appreciated.

+3


source to share


1 answer


Hope I understood your needs correctly.

So, I assume you want the following code in your test:

public void ActivityFiredCorrectly_WhenSomethingDone() {
    // some code that launch activity

    Intent nextStartedActivity = ShadowApplication.getInstance().getNextStartedActivity();

    // check intent parameters
}

      



If that's not enough, you can check the shadow of the intent:

ShadowIntent shadowIntent = shadowOf(nextStartedActivity);

      

Hope it helps

+1


source







All Articles