I’m writing an Android JUnit test and want to copy/reset a test fixture file (it’s an SQLite database file.) If I were within the main application, I know I could just place the file in the assets directory and use getResources().getAssets().open(sourceFile)
However, this API appears to be unavailable from the ActivityInstrumentationTestCase2 class.
Is there an easy way to copy a file over from the testing PC, or should I just keep a fresh copy of a test fixture on the device and copy it over a temporary file?
Thanks!
What I’ve done to accomplish this (in a not very elegant way) is to copy the test fixture onto my device (or emulated device.) I named it “cleantestdatabase.db.” Then in the test code, I copy it to “testdatabase.db,” so that I can modify it with my tests but reset it to a known state. Here’s the code: