How is it possible to use a local (DB on file system) SQLiteDatabase in robolectric 2.3? All solutions on the Internet refer to robolectric < 2.3.
I want to do this, because robolectric does not find the created tables in a second or third test.
How is it possible to use a local (DB on file system) SQLiteDatabase in robolectric 2.3? All solutions on the Internet refer to robolectric < 2.3.
I want to do this, because robolectric does not find the created tables in a second or third test.
 
    
     
    
    I found a solution using a 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()
    {
        return "org.sqlite.JDBC";
    }
    public String getSelectLastInsertIdentity()
    {
        return "SELECT last_insert_rowid() AS id";
    }
    public int getResultSetType()
    {
        return ResultSet.TYPE_FORWARD_ONLY;
    }
    public String getConnectionString(File arg0)
    {
        return String.format("jdbc:sqlite:%s", localDb);
    }
}
Additionally the location of 'DbMap.localDb' was the same as during initializing the DB through 'SQLiteDatabase.openOrCreateDatabase(dbFile.getAbsolutePath(), null);'. Perhaps this is not relevant.
After this you can use a local file-DB in roboletric!
