再来讲说第二种测试方式:sql
前提:须要你的测试工程与被测工程运行在统一进程中,使用InstrumentationTestcase相关的子类。数组
一、获取被测应用的db列表,经过调用ApplicationContext的databaseList;测试
二、自定义一个SQLiteOpenHelper的之类做为操做接口,如:public class DatabaseUtil extends SQLiteOpenHelperspa
三、根据第一步获取的db列表数组,获取被测db,调用DatabaseUtil的构造方法,拿到db的可读可写接口;code
四、拿到dbname下面须要知道具体表名,经过如下执行sql:sqlite
Cursor c = db.rawQuery("select name from sqlite_master where type='table' order by name", null); while(c.moveToNext()){ Log.w("test_DB",c.getString(0)); }
五、如今dbname和tablename都已经知道了,想干吗就干吗了blog
好比:接口
db.query();db.insert();db.update();db.delete();