mercredi 1 avril 2015

How to create SQLite in-memory database without Android Context?

I would like to use OrmLite Dao in unit tests but I don't have access to Context object because I want to run tests on jvm, not on emulator.


To obtain Dao I've used:



public Dao<Tag, Long> getTagDao() {
ConnectionSource connectionSource = new AndroidConnectionSource(SQLiteDatabase.create(null));
return DaoManager.createDao(connectionSource, Tag.class);
}


But it doesn't work because of this exception:



java.lang.RuntimeException: Method create in android.database.sqlite.SQLiteDatabase not mocked. See http://ift.tt/1zlzRtn for details.
at android.database.sqlite.SQLiteDatabase.create(SQLiteDatabase.java)


Is there any possibility to receive in-memory SQLiteDatabase in unit test?


to run unit tests I use android gradle plugin 1.1.3


Aucun commentaire:

Enregistrer un commentaire