According to the official Service Testing documentation it is important to ensure that the onCreate()
is called in response to Context.startService()
and the onDestroy()
is called in response to Context.stopService()
. How can I implement such a test by extending the ServiceTestCase
class?
If you're testing your service using that framework, the system is not taking care of calling your service's onCreate() and onDestroy() methods. Therefore, you need to take care of calling that from the test code.
This is not a test, this is correct startup and shutdown of your service. If you don't call those methods, you can't expect your service to behave properly and your testing will be chasing down phantom bugs.