Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shadow Fragments in Robolectric?

I am currently trying to test drive android code with Robolectric. I need to check that the bundle I am sending with an intent in order to create a new activity contains what I expect it to.

Looking around online, I found mention of ShadowFragment in Robolectric 2.0-alpha 1 documents which has getArguments() that seems like it would do what I need, but it doesn't seem to be mentioned at all in the 2.4 documents and I can't get org.robolectric.shadows.ShadowFragment to resolve.

Has it moved, is there a workaround, or is there another direction that I need to go in order to inspect an activity's bundle in Robolectric?

Any help would be greatly appreciated.

like image 747
James Hollingshead Avatar asked Jan 24 '26 22:01

James Hollingshead


1 Answers

I hope I understood your needs correctly.

So I assume you need next code in your test:

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

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

    // check intent parameters
}

If it is not enough you could inspect shadow of the intent:

ShadowIntent shadowIntent = shadowOf(nextStartedActivity);

Hope it helps

like image 134
Eugen Martynov Avatar answered Jan 26 '26 12:01

Eugen Martynov