vendredi 31 juillet 2015

Inject Context in ActivityInstrumentationTestCase2

I am writing espresso tests for my Android application. I have an ActivityInstrumentationTestCase2, where I want to inject a context to use a test database instead of the actual database.

The test context I create in the setUp() method like this:

@Before
public void setUp() throws Exception {
    super.setUp();
    RenamingDelegatingContext context = 
            new RenamingDelegatingContext(getContext(), "test_");
    mActivity = getActivity();
    // Now how do I inject the new context to the activity?
}

How can I inject this context into my activity? And if I was able to inject it, will it be the new application context, or which context exactly?

I know that in ActivityUnitTestCase there is a method setActivityContext(Context), but in ActivityInstrumentationTestCase2 it is not there. Is there another way to set the context?

Aucun commentaire:

Enregistrer un commentaire