tags:

views:

36

answers:

2

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!)

A: 

Each Activity is a subclass of Context, so you must use your Activities when you need Context. The class Context is not something you instantiate from an application.

ognian
ah, sory I am JUnit testing here - question updated
jax
Then use the getActivity() method. http://developer.android.com/reference/android/test/ActivityInstrumentationTestCase2.html#getActivity()
ognian
A: 

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

Fred Medlin