How to test an IntentService with Robolectric?

Viewed 12221

I'm trying to test the onHandleIntent() method of an IntentService using Robolectric.

I'm starting the service with:

Activity activity = new Activity();
Intent intent = new Intent(activity, MyService.class);
activity.startService(intent);

ShadowActivity shadowActivity = Robolectric.shadowOf(activity);
Intent startedIntent = shadowActivity.getNextStartedService();
assertNotNull(startedIntent);

seems like startedIntent is not null, but onHandleIntent() doesn't seem to be called.

how should I test it ?

5 Answers
Related