This is what I figured out (and solved in my case) :
Somewhere (probably when initializing Google Analytics), there is a call to start a service.
I thought that this call was to start one of my app's services, so I added
Robolectric.getShadowApplication().setComponentNameAndServiceForBindService(
new ComponentName(Robolectric.application, MyService.class),
new StalkerService() {
@Override
public Context getApplicationContext() {
return Robolectric.application;
}
}.onBind(null)
);
in my TestApplication code, before calling super.onCreate
.
Gladly, it solved my problem - no more NPE, and all tests pass.
But, then I noticed that this is very weird solution, since I'm providing Robolectric the binder for my Service and not GA service... But it works, and I'm not sure why.
So, I'm going to leave it here for you to test if it fixes your issues too.