Android Robolectric Support Fragment FragmentTestUtil

By | October 4, 2015

To use Android Support Fragment v4 in Robolectric 3.0 you must add gradle dependency in /app/build.gradle

testCompile 'org.robolectric:shadows-support-v4:3.0'

Then import into your Robolectric testing java class

import org.robolectric.shadows.support.v4.SupportFragmentTestUtil;

then you can create/start android support v4 fragments within your Robolectric testing java class for unit testing:

SupportFragmentTestUtil.startVisibleFragment(fragment);

Cross posted to StackOverflow Android Robolectric Support Fragment.


Related Articles: