How do you get hold of an Android Context for a Junit test from a Java Project?

jax picture jax · Jul 3, 2010 · Viewed 14.8k times · Source

I need to access and Android context for a JUnit Test.

I have tried using MockContext and extending the AndroidTestCase but each time I get an error saying (stub!)

Answer

Fred Medlin picture Fred Medlin · Sep 9, 2010

What about using AndroidTestCase instead of a JUnit test? AndroidTestCase will provide a Context with getContext() that can be used where it's needed.