android - Robolectric: use local SQLiteDatabase -
how possible utilize local (db on file system) sqlitedatabase in robolectric 2.3? solutions on net refer robolectric < 2.3.
i want this, because robolectric not find created tables in sec or 3rd test.
i found solution using specific annotation:
import org.robolectric.util.databaseconfig.usingdatabasemap; import org.robolectric.util.databaseconfig.databasemap; .... @runwith(robolectrictestrunner.class) @usingdatabasemap(dbmap.class) public class generictest{....}
the class dbmap must implement
class dbmap implements databasemap { private static final string localdb = "/users/elcapitano/temp/mydb.db"; public string getdriverclassname() { homecoming "org.sqlite.jdbc"; } public string getselectlastinsertidentity() { homecoming "select last_insert_rowid() id"; } public int getresultsettype() { homecoming resultset.type_forward_only; } public string getconnectionstring(file arg0) { homecoming string.format("jdbc:sqlite:%s", localdb); } }
additionally location of 'dbmap.localdb' same during initializing db through 'sqlitedatabase.openorcreatedatabase(dbfile.getabsolutepath(), null);'. perhaps not relevant.
after can utilize local file-db in roboletric!
android robolectric
No comments:
Post a Comment