I\'m new to Android testing and I\'m trying to create an ApplicationTestCase using a MockContext (well actually I\'m trying to use a Renaming Mock Context). But I keep getti
I've used AndroidTestCase to mock a simple context.
class ExampleTest extends AndroidTestCase
public void setUp() {
Context c = new DelegatedMockContext(getContext())
}
class DelegatedMockContext extends MockContext {
private Context mDelegatedContext;
private static final String PREFIX = "test.";
public DelegatedMockContext(Context context) {
mDelegatedContext = context;
}
@Override
public String getPackageName(){
return PREFIX;
}
@Override
public SharedPreferences getSharedPreferences(String name, int mode) {
return mDelegatedContext.getSharedPreferences(name, mode);
}
}
}
Its just a bog standard Context, but will get you going