strangeoptics
strangeoptics

Reputation: 753

Android: Robolectric: How to use a local data base

I would like to a stable data base with robolectric. The normal behaviour is that the data base is in memory but i wont to have a local data base from the file system.

Upvotes: 1

Views: 1027

Answers (1)

Poly
Poly

Reputation: 1065

I answered the same question in mailing list, but answer here too, just in case.

You can open a prepared database file by SQLiteDatabase class. Please see the following test case as an example: https://github.com/robolectric/robolectric/blob/robolectric-2.1.1/src/test/java/org/robolectric/shadows/SQLiteDatabaseTest.java#L704

Note that disk based SQLite database on 2.1 has some issues e.g. It only works for existing database file, does not create new database file. Those issues are fixed on the master by this pull request: https://github.com/robolectric/robolectric/pull/654

Upvotes: 2

Related Questions