jeudi 1 septembre 2016

Robolectric getSystemService returns null for PowerManager service

I'm trying to unit test some code that uses a library (android priority jobqueue) that requires the powermanager service to exist in some form, but when it tries to access it, getsystemservice returns null, and the library crashes with a NullPointerException.

I've tried:

  • using older code to inject a mock power manager into robolectric, but the code doesn't work anymore due to api changes in 3.0/3.1.
  • using a custom NetworkUtil class for android-priority-jobqueue, but it never does not acknowledge I've set it, and it creates it's own that looks up the power manager.
  • not using robolectric at all, and mocking getsystemservice

Nothing has so far worked. How are people testing code using android-priority-jobqueue, or the powermanager via robolectric? How should it be done?

Thanks :)

Aucun commentaire:

Enregistrer un commentaire