I'm using a RenamingDelegatingContext (RDC) in an ActivityUnitTestCase
to have my application use a database files prefixed by "test." used
during testing.  My application expects a db called "database.sqlite",
so in the setUp() method I create & seed one called
"test.database.sqlite".  I then wrap the context in an RDC with the
prefix "test." and pass it to setActivityContext().

What I see occuring is that the RDC correctly maps calls from my app
for "database.sqlite" to "test.database.sqlite", however it recreates
the db file one first access (my app calls context.openOrCreateDatabase
("database.sqlite", Context.MODE_PRIVATE, null) ).  This destroys all
the seeded test data & causes my tests to fail.

If I just pass in my unwrapped context to the app it works fine (i.e.
doesn't wipe the db file), though obviously it then accesses the app
database, not the test database.  I've observed the state of the /data/
data/<package>/databases directory during test execution & the
"test.database.sqlite" gets created with identical user & access perms
to the original db - in fact I create it using
context.openOrCreateDatabase() then close() it before seeding.

Currently, the way I'm seeding the db is to overwrite it with the
contents of a template .sqlite file from the assets dir, since it
contains a large amount of static data that is prohibitive to insert
every time using SQL scripts (this is also how the app works).
However, I'm written a unit test that shows the RDC overwriting the db
even when seeding is accomplished by executing SQL against
"test.database.sqlite" in the setUp() call.  I've also tried creating
the test database as Context.MODE_WORLD_WRITEABLE with no success.

This seems like a bug to me - unless I'm not understanding how to use
RenamingDelegatingContext properly

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

Reply via email to