SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database (Only when unit testing the app) SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database (Only when unit testing the app) sqlite sqlite

SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database (Only when unit testing the app)


So after some investigation I figured out that the problem lies in the database path

when in test :

/data/data/mehungry.com.myapplicationnavigationdawerdemo.test/databases/MeHungryApp.db

when running whole application:

/data/data/mehungry.com.myapplicationnavigationdawerdemo/databases/MeHungryApp.db

This was the problem, this inconsistency was fixed for me when I did change my DatabaseHelper constructor invocation

from this :

databaseHelper = new DatabaseHelper(InstrumentationRegistry.getContext());

to this :

databaseHelper = new DatabaseHelper(InstrumentationRegistry.getTargetContext());

Hope it might help somebody at somepoint.