Is it possible to read or write files or SQLite databases using an
Instrumentation's Context (i.e. the test project Context, not the
target Context of the package under test)?
For instance, in a ActivityInstrumentationTestCase2 or
ActivityUnitTestCase subclass:
Context testContext = getInstrumentation().getContext();
testContext.getFilesDir() //**RETURNS NULL
testContext.openOrCreateDatabase("my.db",Context.PRIVATE,null): //
**THROWS SQLITEEXCEPTION
testContext.openFileOutput("mytest.txt", 0); //** THROWS NPE
Is this correct/expected?
What does seem to work is testContext.getAssets().open("mytest.txt").
Is this the correct/only way to read in static text,SQL scripts, dummy
data etc from a Test Context?
On a related note, how does one make use of the
RenamingDelegatingContext that takes 2 Contexts? I intended to pass
the testContext for use with file/DB operations & then provide test
versions of my applications database as part of the test project -
however, I cannot create or initialize them in that context. Is the
intent rather to provide a MockContext that provides test content from
the target context?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en