view raw
L. G. L. G. - 11 months ago 44
Android Question

How to access both test and application Context in an Android test?

I need to access both test and application

Context
in a test. I couldn't find an Android test type (
InstrumentationTestCase
,
AndroidTestCase
...) allowing to do it. Any hint?

Answer

Finally found it. Use InstrumentationTestCase with:

  • getInstrumentation().getContext(): to get test Context
  • getInstrumentation().getTargetContext(): to get target application Context