In my Robolectric test I run my fragment by:
sut = new TestedFragment();
SupportFragmentTestUtil.startFragment(sut);
In fragment's onCreateView
I have android.support.v4.app.FragmentTabHost
on which I try to get its tabWidget
using:
inflatedView = inflater.inflate(R.layout.some_layout, container, false);
tabHost = (FragmentTabHost) inflatedView.findViewById(android.R.id.tabhost);
fragmentManager = getChildFragmentManager();
tabHost.setup(getActivity(), fragmentManager, android.R.id.tabcontent);
tabHost.getTabWidget(); //returns null
This line returns null although set up breakpoint on this line shows me that tabHost
's mTabWidget
has value of
android.widget.TabWidget{7a4d42e6 V.E..... ......I. 0,0-0,0 #1020013 android:id/tabs}
so why do I get null
?
The code works on android, i doesn't work in roboelectric unit test