How can I use a real Application object with Android's ServiceTestCase

514 Views Asked by At

I'm trying to test a service that requires a real Application object, not the MockApplication that the ServiceTestCase provides.

How can I create a real Application object in my ServiceTestCase?

1

There are 1 best solutions below

1
Diego Torres Milano On

A service has two inherent dependencies, its Context and its associated Application. The ServiceTestCase framework allows you to inject these dependencies, and thus perform unit tests with controlled dependencies in an isolated environment.

You should not use the real Application in your tests, but if you know what you are doing you can inject it using ServiceTestCase.setApplication().