I want to test the UserConnectFragment fragment that contains the PlateformConnect variable. This class has a Facebook SDK initialization method:
@Override public void create() { FacebookSdk.sdkInitialize(MyApplication.getInstance().getApplicationContext()); }
I have expanded the Android application with the MyApplication class.
In UserConnectFragment, I use PlateformConnect as follows:
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState);
In my Robolectric class class:
@Before public void setUp() throws Exception {
This test fails:
java.lang.NullPointerException at com.xxx.yyyy.ui.intro.UserConnectFragment.onViewCreated(UserConnectFragment.java:77)
And this error appears because I use:
MyApplication.getInstance().getApplicationContext()
... and getInstance () returns null.
In my application, I use MyApplication.getInstance () in many classes, so how can I do this with Robolectric ??
Thanks guys!
source share