Issue
I'm trying to get my tests working with Robolectric.setupActivity(LoginActivity.class);
where my class uses the facebook sdk 4.0 for login. Even though I added FacebookSdk.sdkInitialize(this);
as below:
public class LoginActivity extends FragmentActivity {
private FragmentManager fragmentManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
FacebookSdk.sdkInitialize(this);
if (savedInstanceState == null) {
fragmentManager = getSupportFragmentManager();
...
}
}
I get the following error in my tests:
java.lang.RuntimeException at LoginActivityTest.java:32
Caused by: com.facebook.FacebookSdkNotInitializedException at LoginActivityTest.java:32
Here is my test class:
@RunWith(CustomRobolectricRunner.class)
@Config(emulateSdk = 21, reportSdk = 21, constants = BuildConfig.class)
public class LoginActivityTest {
private Button loginButton;
private ShadowActivity loginActivityShadow;
@Before
public void setUp() throws Exception
{
LoginActivity activity = Robolectric.setupActivity(LoginActivity.class);
loginButton = (Button) activity.findViewById(R.id.loginButton);
loginActivityShadow = Shadows.shadowOf(activity);
}
@Test
public void shouldStartFacebookActivityWhenLoginButtonIsClicked()
{
Intent intent = loginActivityShadow.getNextStartedActivity();
loginButton.performClick();
//assertThat(activity, new StartedMatcher(com.facebook.LoginActivity.class));
}
}
Thank you for your help.
Solution
You will need to call FacebookSdk.sdkInitialize(this);
before you call setContentView(R.layout.activity_login);
.
Answered By - Gokhan Caglar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.