{"id":473,"date":"2015-10-04T11:44:32","date_gmt":"2015-10-04T11:44:32","guid":{"rendered":"http:\/\/installingcats.com\/?p=473"},"modified":"2015-10-04T11:44:32","modified_gmt":"2015-10-04T11:44:32","slug":"android-robolectric-support-fragment-fragmenttestutil","status":"publish","type":"post","link":"https:\/\/installingcats.com\/2015\/10\/04\/android-robolectric-support-fragment-fragmenttestutil\/","title":{"rendered":"Android Robolectric Support Fragment FragmentTestUtil"},"content":{"rendered":"
To use\u00a0Android Support Fragment v4 in\u00a0Robolectric 3.0 you must add gradle dependency in \/app\/build.gradle<\/p>\n
testCompile 'org.robolectric:shadows-support-v4:3.0'<\/pre>\nThen import into your Robolectric testing java class<\/p>\n
import org.robolectric.shadows.support.v4.SupportFragmentTestUtil;<\/pre>\nthen you can create\/start android support v4 fragments within your Robolectric testing java class for unit testing:<\/p>\n
SupportFragmentTestUtil.startVisibleFragment(fragment);<\/pre>\n