I would like to get started writing some test for my database. How would I write a test for the onCreate Method for MyDatabaseHelper class?
public class MyDatabaseHelper extends SQLiteOpenHelper {
private Context context;
private static final String DATABASE_NAME = "Contacts.db";
private static final int DATABASE_VERSION = 1;
private static final String TABLE_NAME = "contacts";
private static final String COLUMN_ID = "_id";
private static final String COLUMN_FIRST_NAME = "first_name";
private static final String COLUMN_LAST_NAME = "last_name";
private static final String COLUMN_PHONE = "_phone";
//constructor
MyDatabaseHelper(@Nullable Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.context = context;
}
//Create DB
@Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE_NAME +
" (" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COLUMN_FIRST_NAME + " TEXT, " +
COLUMN_LAST_NAME + " TEXT, " +
COLUMN_PHONE + " TEXT);";
db.execSQL(query);
}
Aucun commentaire:
Enregistrer un commentaire