3

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?

Dan Devine
  • 859
  • 1
  • 8
  • 19

1 Answers1

0

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().

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • 1
    I got that far alright. I've been able see where you can inject both of these, I simply can't see how to create either a real Application object (as opposed to the MockApplication that comes with ServiceTestCase) or an Application object in a ContextWrapper (similar to methods available in ActivityInstrumentationTestCase2). I went so far as to attempt creating an ApplicationTestCase as an inner class to the ServiceTestCase. None of these approaches work. I'm attempting to test my service's set/update of the system notifications, and the OS needs a real Application to function. – Dan Devine May 26 '12 at 15:46