[ Robolectric with third party libraries ]
My project include several third party libraries like crashlytics, facebook sdk and so on. Some of them require to do initialization on activity startup, however under gradle unit test it will fails, how to avoid this? mocking or use a runtime flag to bypass it?
Answer 1
Both ways would work, but mocking is better IMO. For static methods you'll need to wrap them in non-static context as well, so Mockito can do its magic. Also, you can do assertions on your logs now.
Crashlytics, you would wrap with Logger interface instance:
public interface Logger {
void setup(Context context);
....
}
And the Wrapper itself would call the static context:
public class CrashlyticsLogger implements Logger {
@Override
public void setup(Context context) {
Fabric.with(context, new Crashlytics());
}
...
}