I'm trying to create a database that contains mock objects for testing purposes. I'd prefer to have this db reside in my test package instead of in my application package.
protected class MockObjectOpenHelper extends SQLiteOpenHelper {
MockObjectOpenHelper() {
super(instrumentation.getContext(), FILE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
...
}
}
When I create my SQLiteOpenHelper from within my app, I pass in the instrumentation context as well as a path that's relative to my test package's database directory. I would think this would allow me to create a database in my test package, but this doesn't seem to be the case. The "databases" directory is never created in my test package.
Is there a way to have my app create and access a database that resides in my test project?
The exception:
14:50:13.917 pool-1-thread-1 android.database.sqlite.SQLiteException: unable to open database file
at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1584)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:638)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:659)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:652)
at android.app.ApplicationContext.openOrCreateDatabase(ApplicationContext.java:482)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)
at com.myapp.test.http.DbMockHttpClient.createClientRequestDirector(DbMockHttpClient.java:52)
at com.myapp.test.http.UniversalMockHttpClient.createClientRequestDirector(UniversalMockHttpClient.java:42)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:539)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
E
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…