Android自動化測試之路——Provider(二)

再來講說第二種測試方式: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();
相關文章
相關標籤/搜索