I am trying to figure out how to use RenamingDelegatingContext
to mock a database for testing purposes. The tutorials I have found about this class are great but don't quite answer my questions.
- dtmilano discusses mocking a file with
RenamingDelegatingContext
. - jayway gives a tutorial about mocking a
ContentResolver
, but only focus onopenInputStream()
rather thanquery()
and the other database-like operations
As far as I can tell, there isn't a tutorial about mocking databases. If I am missing it in my googling, please provide a link. Otherwise, this would be an excellent home for such a tutorial.
Update:
Testing database on Android: ProviderTestCase2 or RenamingDelegatingContext? is close to what I am trying to do. The difference is that I have already written tests for my ContentProvider
using ProviderTestCase2
. Now I am doing some functional testing with ActivityInstrumentationTestCase2
subclasses for some activities which use that ContentProvider
. I need the instrumentation for menu and button clicks. If I create a mock context with
RenamingDelegatingContext context =
new RenamingDelegatingContext(getTargetContext(), TEST_FILE_PREFIX);
how and when do I inject it into the instrumentation?